SPB Git

Repository Public

BrowserView.swift 33.2 KB 651 lines swift

1import SwiftUI2import UIKit3import WebKit45/// Root of a scene: touch-first chrome on iPhone (one floating bar within thumb reach), sidebar + top bar on iPad.6struct BrowserView: View {7    @Bindable var model: BrowserModel8    let environment: MobileEnvironment9    @Environment(\.horizontalSizeClass) private var sizeClass10    @Environment(\.auraPolicy) private var policy11    @AppStorage("addressBarAtBottom") private var addressBarAtBottom = true12    @State private var sidebarVisibility: NavigationSplitViewVisibility = .detailOnly1314    /// Constellation and Canvas take the whole screen; Flow and Portal come as sheets.15    private var coverSurface: Binding<BrowserModel.AuraSurface?> {16        Binding(get: { model.auraSurface.flatMap { $0 == .constellation || $0 == .canvas ? $0 : nil } }, set: { if $0 == nil { model.auraSurface = nil } })17    }18    private var sheetSurface: Binding<BrowserModel.AuraSurface?> {19        Binding(get: { model.auraSurface.flatMap { $0 == .flow || $0 == .portal ? $0 : nil } }, set: { if $0 == nil { model.auraSurface = nil } })20    }2122    var body: some View {23        Group {24            if sizeClass == .regular { padLayout } else { phoneLayout }25        }26        .overlay { if model.isEditingAddress { AddressEditor(model: model, environment: environment).transition(AuraTransition.depth(policy, anchor: .bottom)) } }27        .auraAnimation(.standard, value: model.isEditingAddress)28        .overlay { AuraCommandLayer(model: model, environment: environment) }29        .overlay(alignment: .top) { AuraToast(text: $model.toast, edge: .top).padding(.top, 8).padding(.horizontal, 12) }30        .fullScreenCover(isPresented: $model.showsTabOverview) { TabOverview(model: model, environment: environment) }31        .fullScreenCover(item: coverSurface) { surface in32            Group {33                if surface == .canvas {34                    CanvasBoardView(controller: model.canvas, host: model.canvasHost)35                } else {36                    ConstellationScreen(model: model, onFinish: { model.auraSurface = nil })37                }38            }39            .auraRoot(decorative: environment.settings.ambientMotionEnabled)40        }41        .sheet(item: sheetSurface) { surface in42            Group {43                if surface == .flow { FlowSheet(model: model, environment: environment) } else { PortalSheet(model: model, environment: environment) }44            }45            .auraRoot(decorative: environment.settings.ambientMotionEnabled)46            .presentationDetents([.large])47            .presentationDragIndicator(.visible)48        }49        .sheet(item: $model.library) { section in50            LibrarySheet(model: model, environment: environment, initial: section)51        }52        .sheet(isPresented: $model.showsSettings) { MobileSettingsView(model: model, environment: environment) }53        .sheet(item: $model.bookmarkDraft) { draft in BookmarkEditor(draft: draft, model: model, environment: environment) }54        .confirmationDialog(L("Open this link in another app?"), isPresented: Binding(get: { model.pendingExternal != nil }, set: { if !$0 { model.pendingExternal = nil } }),55                            titleVisibility: .visible) {56            Button(L("Open")) { if let url = model.pendingExternal { UIApplication.shared.open(url) }; model.pendingExternal = nil }57            Button(L("Cancel"), role: .cancel) { model.pendingExternal = nil }58        } message: { Text(L("The page wants to open a “%@:” link outside SP Browser.", model.pendingExternal?.scheme ?? "")) }59        .onChange(of: model.focusMode) { _, focused in if focused { sidebarVisibility = .detailOnly } }60    }6162    // MARK: iPhone6364    /// The page fills the screen down to its bottom edge; the bar floats over it. The web view keeps room for the bar65    /// through its content inset, so nothing is resized while the bar contracts and expands.66    private var phoneLayout: some View {67        GeometryReader { proxy in68            let showsTopBar = !addressBarAtBottom && !model.focusMode69            let reserved = (model.focusMode ? 44 : FloatingBar.expandedHeight(showsAddress: addressBarAtBottom)) + proxy.safeAreaInsets.bottom + 670            ZStack(alignment: .bottom) {71                VStack(spacing: 0) {72                    if showsTopBar { PhoneAddressBar(model: model, atBottom: false).padding(.horizontal, 12).padding(.top, 4).padding(.bottom, 8).transition(AuraTransition.rise(.top, policy)) }73                    PageContainer(model: model, environment: environment, bottomInset: reserved)74                }75                .ignoresSafeArea(.container, edges: .bottom)76                FloatingBar(model: model, environment: environment, showsAddress: addressBarAtBottom)77            }78            .auraAnimation(.expressive, value: showsTopBar)79        }80        .background(chromeBackground.ignoresSafeArea())81        .ignoresSafeArea(.keyboard, edges: .bottom)82    }8384    private var chromeBackground: some View {85        ZStack { Aura.Palette.chrome; if model.isPrivate { Aura.Palette.violet.opacity(0.18) } }86    }8788    // MARK: iPad8990    private var padLayout: some View {91        NavigationSplitView(columnVisibility: $sidebarVisibility) {92            PadSidebar(model: model, environment: environment)93                .navigationSplitViewColumnWidth(min: 280, ideal: 320, max: 380)94        } detail: {95            VStack(spacing: 0) {96                if !model.focusMode {97                    VStack(spacing: 0) {98                        PadTopBar(model: model, environment: environment, sidebar: $sidebarVisibility)99                        PadTabStrip(model: model)100                        Rectangle().fill(Aura.Palette.hairline).frame(height: 1)101                    }102                    .transition(AuraTransition.rise(.top, policy))103                }104                PageContainer(model: model, environment: environment)105            }106            .overlay(alignment: .top) {107                if model.focusMode {108                    FocusControl(model: model)109                        .padding(.top, 10).transition(AuraTransition.depth(policy, anchor: .top))110                }111            }112            .background(chromeBackground.ignoresSafeArea())113            .toolbar(.hidden, for: .navigationBar)114        }115        .navigationSplitViewStyle(.balanced)116    }117}118119extension BrowserModel {120    /// Reading progress shown by the Focus pill: only for a page long enough for it to mean something.121    var focusProgress: Double? {122        guard let tab = selectedTab, tab.showsWebPage, tab.readerArticle == nil, tab.isLongPage else { return nil }123        return tab.readingProgress124    }125}126127// MARK: - Page area128129/// Shows the selected tab: start page, web page, native search results, or an error.130struct PageContainer: View {131    @Bindable var model: BrowserModel132    let environment: MobileEnvironment133    /// Height hidden by the floating bar at the bottom of the page area (iPhone); zero on iPad.134    var bottomInset: CGFloat = 0135136    var body: some View {137        ZStack {138            if let tab = model.selectedTab {139                TabPage(tab: tab, model: model, environment: environment, bottomInset: bottomInset).id(tab.id)140            } else {141                Aura.Palette.surface142            }143        }144        .frame(maxWidth: .infinity, maxHeight: .infinity)145        .background(Aura.Palette.surface)146        .clipped()147        .dropDestination(for: URL.self) { urls, _ in148            guard let url = urls.first, ["http", "https"].contains(url.scheme?.lowercased() ?? "") else { return false }149            model.open(url, inNewTab: !(model.selectedTab?.isBlank ?? true))150            return true151        }152    }153}154155struct TabPage: View {156    @Bindable var tab: MobileTab157    let model: BrowserModel158    let environment: MobileEnvironment159    var bottomInset: CGFloat = 0160    @Environment(\.auraPolicy) private var policy161162    /// Native pages (start page, results, errors, reader) scroll clear of the floating bar.163    private var barSpace: some View { Color.clear.frame(height: bottomInset).allowsHitTesting(false) }164165    var body: some View {166        ZStack(alignment: .top) {167            if tab.isBlank {168                MobileStartPage(model: model, environment: environment, tab: tab).safeAreaInset(edge: .bottom, spacing: 0) { barSpace }169            } else {170                WebViewHost(tab: tab, bottomInset: bottomInset)171                    .opacity(tab.failure == nil && !tab.isSearchPage ? 1 : 0)172                    .accessibilityHidden(tab.isSearchPage || tab.failure != nil || tab.readerArticle != nil)173                if tab.isSearchPage {174                    Group {175                        if let page = tab.searchPage {176                            SearchResultsView(model: page, actions: model.searchActions(for: tab))177                        } else {178                            Aura.Palette.surface.task { tab.refreshSearchPage() }179                        }180                    }181                    .safeAreaInset(edge: .bottom, spacing: 0) { barSpace }182                }183                if let failure = tab.failure { PageFailureView(failure: failure) { tab.reload() }.safeAreaInset(edge: .bottom, spacing: 0) { barSpace } }184                if let article = tab.readerArticle {185                    AuraReaderView(article: article, url: tab.url, showsTrail: environment.settings.focusTrailEnabled, onClose: { AuraMotion.perform(.standard) { tab.readerArticle = nil } })186                        .safeAreaInset(edge: .bottom, spacing: 0) { barSpace }187                        .transition(AuraTransition.depth(policy, anchor: .center))188                }189            }190            if tab.isLoading, !tab.isSearchPage {191                AuraProgressIndicator(progress: max(tab.progress, 0.04), thickness: 2.5).transition(.opacity)192            } else if model.focusMode, environment.settings.focusTrailEnabled, tab.showsWebPage, tab.readerArticle == nil, tab.isLongPage {193                FocusTrail(progress: tab.readingProgress).transition(.opacity)194            }195        }196        .auraAnimation(.standard, value: tab.readerArticle != nil)197        .auraAnimation(.quick, value: tab.isLoading)198    }199}200201/// Hosts the tab's own WKWebView, so switching tabs never reloads a page.202struct WebViewHost: UIViewRepresentable {203    let tab: MobileTab204    var bottomInset: CGFloat = 0205206    func makeUIView(context: Context) -> UIView {207        let container = UIView()208        container.backgroundColor = .clear209        return container210    }211212    func updateUIView(_ container: UIView, context: Context) {213        let webView = tab.ensureWebView()214        tab.setBottomInset(bottomInset)215        guard webView.superview !== container else { return }216        container.subviews.forEach { $0.removeFromSuperview() }217        webView.removeFromSuperview()218        webView.frame = container.bounds219        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]220        container.addSubview(webView)221    }222}223224struct PageFailureView: View {225    let failure: PageFailure226    let retry: () -> Void227228    var body: some View {229        VStack(spacing: 12) {230            Image(systemName: failure.isOffline ? "wifi.slash" : "exclamationmark.triangle").font(.system(size: 44, weight: .light)).foregroundStyle(.secondary).accessibilityHidden(true)231            Text(failure.title).font(.title3.weight(.semibold)).multilineTextAlignment(.center)232            Text(failure.message).font(.callout).foregroundStyle(.secondary).multilineTextAlignment(.center)233            if let host = failure.url?.host { Text(host).font(.footnote.monospaced()).foregroundStyle(.tertiary) }234            Button(L("Try Again"), action: retry).buttonStyle(.borderedProminent).padding(.top, 6)235        }236        .padding(32)237        .frame(maxWidth: .infinity, maxHeight: .infinity)238        .background(Aura.Palette.surface)239        .accessibilityIdentifier("page-failure")240    }241}242243244// MARK: - iPhone chrome245246/// The collapsed address field: tap to edit, swipe sideways to change tab (it follows the finger), swipe up for all tabs.247struct PhoneAddressBar: View {248    @Bindable var model: BrowserModel249    let atBottom: Bool250    @State private var drag: CGFloat = 0251    @Environment(\.auraPolicy) private var policy252253    /// Distance, in points, that counts as a full swipe to the next tab.254    private static let swipeDistance: CGFloat = 150255256    var body: some View {257        let tab = model.selectedTab258        HStack(spacing: 8) {259            Image(systemName: tab?.isSearchPage == true || tab?.isBlank != false ? "magnifyingglass" : (tab?.isSecure == true ? "lock.fill" : "exclamationmark.triangle"))260                .font(.system(size: 12, weight: .semibold)).foregroundStyle(tab?.isBlank == false && tab?.isSearchPage == false && tab?.isSecure == false ? Color.orange : .secondary)261                .accessibilityHidden(true)262            Text(tab?.addressText.isEmpty == false ? tab!.addressText : L("Search or enter address"))263                .font(.system(size: 16)).lineLimit(1).truncationMode(.middle)264                .foregroundStyle(tab?.addressText.isEmpty == false ? .primary : .secondary)265                .frame(maxWidth: .infinity)266            if let tab, !tab.isBlank {267                Button { tab.isLoading ? tab.stopLoading() : tab.reload() } label: {268                    Image(systemName: tab.isLoading ? "xmark" : "arrow.clockwise").font(.system(size: 13, weight: .semibold)).contentTransition(.symbolEffect(.replace))269                        .frame(width: 30, height: 30).contentShape(Rectangle())270                }271                .buttonStyle(AuraPressStyle(scale: 0.85)).foregroundStyle(.secondary)272                .accessibilityLabel(tab.isLoading ? L("Stop Loading") : L("Reload Page"))273            }274        }275        .padding(.leading, 14).padding(.trailing, 6)276        .frame(height: 44)277        .auraField(focused: false, radius: 15, tint: model.isPrivate ? Aura.Palette.violet.opacity(0.6) : nil)278        .contentShape(Rectangle())279        .offset(x: drag)280        .opacity(1 - min(abs(drag) / (Self.swipeDistance * 2.2), 0.55))281        .onTapGesture { model.isEditingAddress = true }282        .gesture(DragGesture(minimumDistance: 14)283            .onChanged { value in284                guard abs(value.translation.width) > abs(value.translation.height) else { return }285                // With a tab on that side the field tracks the finger; with none it resists, like the edge of a scroll view.286                drag = model.visibleTabs.count > 1 ? value.translation.width287                    : CGFloat(GestureResolution.rubberBand(Double(value.translation.width), limit: 70))288            }289            .onEnded { value in290                let horizontal = abs(value.translation.width) > abs(value.translation.height)291                let direction: CGFloat = value.translation.width < 0 ? -1 : 1292                let progress = Double(abs(value.translation.width) / Self.swipeDistance)293                let velocity = Double(value.velocity.width * direction / Self.swipeDistance)294                if horizontal, model.visibleTabs.count > 1, GestureResolution.shouldCommit(progress: progress, velocity: velocity) {295                    model.selectAdjacentTab(offset: direction < 0 ? 1 : -1)296                    // The next tab's address arrives from the side the finger was heading away from.297                    if policy.allowsSpatial { drag = -direction * 90 }298                    withAnimation(AuraMotion.animation(.spring, policy: policy)) { drag = 0 }299                } else {300                    withAnimation(AuraMotion.animation(.spring, policy: policy)) { drag = 0 }301                    if !horizontal, value.translation.height < -50 { model.selectedTab?.captureThumbnail(); model.showsTabOverview = true }302                }303            })304        .contextMenu {305            if let url = tab?.url, HistoryStore.isRecordable(url) {306                Button { PlatformActions.copy(url.absoluteString) } label: { Label(L("Copy Link"), systemImage: "doc.on.doc") }307            }308            Button { if let text = UIPasteboard.general.string { model.navigate(text) } } label: { Label(L("Paste and Go"), systemImage: "doc.on.clipboard") }309        }310        .accessibilityElement(children: .ignore)311        .accessibilityLabel(L("Address and search"))312        .accessibilityValue(tab?.addressText ?? "")313        .accessibilityAddTraits(.isButton)314        .accessibilityIdentifier("address-bar")315    }316}317318/// AURA Floating Navigation: the address field and the controls in one glass bar within thumb reach. It contracts to a319/// small pill while the user scrolls down a page and comes back on scroll up, on tap, or at the top of the page.320struct FloatingBar: View {321    @Bindable var model: BrowserModel322    let environment: MobileEnvironment323    let showsAddress: Bool324    @Environment(\.auraPolicy) private var policy325326    private enum Shape: Equatable { case full, compact, focus }327328    static func expandedHeight(showsAddress: Bool) -> CGFloat { showsAddress ? 106 : 54 }329330    private var shape: Shape {331        if model.focusMode { return .focus }332        if model.selectedTab?.prefersCompactChrome == true, !model.isEditingAddress, !model.showsOrbit { return .compact }333        return .full334    }335336    var body: some View {337        let tab = model.selectedTab338        ZStack(alignment: .bottom) {339            switch shape {340            case .focus:341                FocusControl(model: model)342                    .padding(.bottom, 4)343                    .transition(AuraTransition.depth(policy, anchor: .bottom))344            case .compact:345                if let tab { CompactPill(tab: tab, isPrivate: model.isPrivate).padding(.bottom, 2).transition(AuraTransition.depth(policy, anchor: .bottom)) }346            case .full:347                full(tab).transition(AuraTransition.depth(policy, anchor: .bottom))348            }349        }350        .frame(maxWidth: .infinity)351        .padding(.horizontal, 10).padding(.bottom, 4)352        // A spring: a new scroll direction can interrupt it at any point and it continues from where it is.353        .auraAnimation(.spring, value: shape)354    }355356    private func full(_ tab: MobileTab?) -> some View {357        VStack(spacing: 2) {358            if showsAddress { PhoneAddressBar(model: model, atBottom: true).padding(.horizontal, 8) }359            HStack(spacing: 0) {360                ToolbarIcon(symbol: "chevron.left", label: L("Back")) { model.perform(.goBack) }.disabled(!model.isEnabled(.goBack))361                Spacer(minLength: 0)362                ToolbarIcon(symbol: "chevron.right", label: L("Forward")) { model.perform(.goForward) }.disabled(!model.isEnabled(.goForward))363                Spacer(minLength: 0)364                PageMenu(model: model, environment: environment)365                Spacer(minLength: 0)366                OrbitLauncher(model: model)367                Spacer(minLength: 0)368                ToolbarIcon(symbol: "book", label: L("Bookmarks")) { model.perform(.showBookmarks) }.accessibilityIdentifier("library-button")369                Spacer(minLength: 0)370                TabsButton(model: model)371            }372            .padding(.horizontal, 10)373            .frame(height: 44)374        }375        .padding(.top, showsAddress ? 8 : 3).padding(.bottom, 3)376        .auraSurface(.floating, radius: Aura.Radius.xxl, tint: model.isPrivate ? Aura.Palette.violet : nil)377        .accessibilityElement(children: .contain)378    }379}380381/// The contracted bar: the site and a thin line (loading, then how far down the page the reader is).382struct CompactPill: View {383    @Bindable var tab: MobileTab384    let isPrivate: Bool385386    var body: some View {387        Button { tab.expandChrome(); AuraHaptics.play(.tap) } label: {388            HStack(spacing: 6) {389                Image(systemName: tab.isSecure ? "lock.fill" : "exclamationmark.triangle").font(.system(size: 9.5, weight: .semibold))390                    .foregroundStyle(tab.isSecure ? AnyShapeStyle(.secondary) : AnyShapeStyle(Color.orange))391                Text(tab.addressText).font(.system(size: 12.5, weight: .medium)).lineLimit(1).truncationMode(.middle)392            }393            .padding(.horizontal, 16)394            .frame(height: 30)395            .frame(minWidth: 132, maxWidth: 260)396            .overlay(alignment: .bottom) {397                AuraProgressIndicator(progress: tab.isLoading ? max(tab.progress, 0.04) : tab.readingProgress, thickness: 2,398                                      label: tab.isLoading ? "" : L("Reading progress"))399                    .padding(.horizontal, 14).padding(.bottom, 3)400            }401            .auraSurface(.floating, radius: 15, tint: isPrivate ? Aura.Palette.violet : nil)402            .contentShape(Rectangle())403        }404        .buttonStyle(AuraPressStyle(scale: 0.95))405        .fixedSize()406        .accessibilityElement(children: .ignore)407        .accessibilityLabel(L("Show the toolbar"))408        .accessibilityValue(tab.addressText)409        .accessibilityAddTraits(.isButton)410        .accessibilityIdentifier("floating-pill")411    }412}413414struct ToolbarIcon: View {415    let symbol: String416    let label: String417    let action: () -> Void418    @Environment(\.isEnabled) private var isEnabled419    @State private var hovering = false420421    var body: some View {422        Button(action: action) {423            Image(systemName: symbol).font(.system(size: 19, weight: .regular)).frame(width: 44, height: 40)424                .background(RoundedRectangle(cornerRadius: Aura.Radius.m, style: .continuous).fill(hovering && isEnabled ? Aura.Palette.hover : .clear))425                .contentShape(Rectangle())426        }427        .buttonStyle(AuraPressStyle(scale: 0.88))428        .foregroundStyle(isEnabled ? Aura.Palette.accent : Color.secondary.opacity(0.4))429        .onHover { hovering = $0 }430        .accessibilityLabel(label)431    }432}433434/// Opens Command Orbit: the few commands that fit what is on screen.435struct OrbitLauncher: View {436    @Bindable var model: BrowserModel437438    var body: some View {439        Button { model.perform(.commandOrbit) } label: {440            Image(systemName: "circle.hexagongrid").font(.system(size: 19, weight: .medium)).foregroundStyle(Aura.gradient)441                .frame(width: 44, height: 40).contentShape(Rectangle())442        }443        .buttonStyle(AuraPressStyle(scale: 0.86))444        .contextMenu { Button { model.perform(.commandPalette) } label: { Label(L("All commands"), systemImage: "command") } }445        .accessibilityLabel(L("Command Orbit"))446        .accessibilityIdentifier("orbit-button")447    }448}449450struct TabsButton: View {451    @Bindable var model: BrowserModel452453    var body: some View {454        Button { model.selectedTab?.captureThumbnail(); model.showsTabOverview = true } label: {455            ZStack {456                RoundedRectangle(cornerRadius: 5, style: .continuous).strokeBorder(lineWidth: 1.6).frame(width: 22, height: 22)457                Text("\(min(model.visibleTabs.count, 99))").font(.system(size: 11, weight: .bold, design: .rounded)).contentTransition(.numericText())458            }459            .frame(width: 44, height: 40).contentShape(Rectangle())460        }461        .buttonStyle(AuraPressStyle(scale: 0.88))462        .foregroundStyle(model.isPrivate ? Aura.Palette.violet : Aura.Palette.accent)463        .contextMenu {464            Button { model.perform(.newTab) } label: { Label(L("New Tab"), systemImage: "plus.square") }465            Button { model.perform(.newPrivateWindow) } label: { Label(L("New Private Tab"), systemImage: "eyeglasses") }466            Button { model.perform(.showConstellation) } label: { Label(CommandID.showConstellation.title, systemImage: OrbitCatalog.symbol(.showConstellation)) }467            if model.selectedTab != nil { Button(role: .destructive) { model.perform(.closeTab) } label: { Label(L("Close Tab"), systemImage: "xmark") } }468            if !model.recentlyClosed.isEmpty { Button { model.perform(.reopenClosedTab) } label: { Label(L("Reopen Closed Tab"), systemImage: "arrow.uturn.backward") } }469        }470        .accessibilityLabel(L("%d tabs", model.visibleTabs.count))471        .accessibilityIdentifier("tabs-button")472    }473}474475/// Share and page actions (the middle button on iPhone, the ellipsis on iPad). Every item runs through the command executor.476struct PageMenu: View {477    @Bindable var model: BrowserModel478    let environment: MobileEnvironment479    var symbol = "square.and.arrow.up"480481    private func item(_ command: CommandID, _ title: String? = nil, symbol: String? = nil) -> some View {482        Button { model.perform(command) } label: { Label(title ?? command.title, systemImage: symbol ?? OrbitCatalog.symbol(command)) }483            .disabled(!model.isEnabled(command))484    }485486    var body: some View {487        let tab = model.selectedTab488        let pageURL = tab?.url.flatMap { HistoryStore.isRecordable($0) ? $0 : nil }489        Menu {490            if let pageURL, let tab {491                item(.sharePage)492                Button { PlatformActions.copy(pageURL.absoluteString); model.toast = L("Link copied") } label: { Label(L("Copy Link"), systemImage: "doc.on.doc") }493                Divider()494                item(.addBookmark, environment.bookmarks.isBookmarked(pageURL.absoluteString) ? L("Edit Bookmark…") : L("Add Bookmark…"))495                if !tab.isPrivate {496                    item(.toggleFavorite, environment.services.library.isFavorite(pageURL.absoluteString) ? L("Remove from Favorites") : L("Add to Favorites"), symbol: "star")497                    item(.addToReadingList)498                }499                item(.findInPage)500                item(.toggleReader)501                item(.addToCanvas)502                Divider()503            }504            item(.toggleFocusMode)505            Menu {506                item(.showFlow)507                item(.showCanvas)508                item(.showConstellation)509                item(.showPortal)510                item(.commandPalette, L("All commands"), symbol: "command")511            } label: { Label("AURA", systemImage: "sparkles") }512            Divider()513            item(.newTab, symbol: "plus.square")514            item(.newPrivateWindow, L("New Private Tab"))515            if !model.recentlyClosed.isEmpty { item(.reopenClosedTab, symbol: "arrow.uturn.backward") }516            Divider()517            item(.showHistory, L("History"))518            item(.showDownloads, L("Downloads"), symbol: "arrow.down.circle")519            item(.openSettings)520        } label: {521            Image(systemName: symbol).font(.system(size: 19)).frame(width: 44, height: 40).contentShape(Rectangle())522        }523        .accessibilityLabel(L("Share and more"))524        .accessibilityIdentifier("page-menu")525    }526}527528// MARK: - iPad chrome529530struct PadTopBar: View {531    @Bindable var model: BrowserModel532    let environment: MobileEnvironment533    @Binding var sidebar: NavigationSplitViewVisibility534535    var body: some View {536        HStack(spacing: 4) {537            ToolbarIcon(symbol: "sidebar.leading", label: L("Show or Hide Sidebar")) {538                AuraMotion.perform(.standard) { sidebar = sidebar == .detailOnly ? .all : .detailOnly }539            }540            .accessibilityIdentifier("sidebar-toggle")541            ToolbarIcon(symbol: "chevron.left", label: L("Back")) { model.perform(.goBack) }.disabled(!model.isEnabled(.goBack))542            ToolbarIcon(symbol: "chevron.right", label: L("Forward")) { model.perform(.goForward) }.disabled(!model.isEnabled(.goForward))543            PhoneAddressBar(model: model, atBottom: false).frame(maxWidth: 760).frame(maxWidth: .infinity).padding(.horizontal, 8)544            PageMenu(model: model, environment: environment)545            OrbitLauncher(model: model)546            ToolbarIcon(symbol: "plus", label: L("New Tab")) { model.newTab() }547            TabsButton(model: model)548        }549        .padding(.horizontal, 10).padding(.top, 4).padding(.bottom, 2)550    }551}552553/// Horizontal tab strip under the iPad top bar: AURA tabs, one selection shape that glides from tab to tab.554struct PadTabStrip: View {555    @Bindable var model: BrowserModel556    @Namespace private var strip557    @Environment(\.auraPolicy) private var policy558559    var body: some View {560        ScrollViewReader { proxy in561            ScrollView(.horizontal, showsIndicators: false) {562                HStack(spacing: 4) {563                    ForEach(model.visibleTabs) { tab in564                        let selected = tab.id == model.selectedTabID565                        AuraTab(title: tab.displayTitle, isSelected: selected, accent: tab.isPrivate && selected ? Aura.Palette.violet : nil, namespace: strip,566                                closeLabel: L("Close Tab"), onClose: { AuraMotion.perform(.spring) { model.close(tab) } }) {567                            Image(systemName: tab.isSearchPage ? "magnifyingglass" : (tab.isPrivate ? "eyeglasses" : "globe")).font(.caption).foregroundStyle(.secondary)568                        }569                        .frame(width: 190)570                        .onTapGesture { AuraMotion.perform(.spring) { model.select(tab) } }571                        .draggable(tab.url ?? URL(string: "about:blank")!)572                        .contextMenu {573                            Button { model.select(tab); model.perform(.duplicateTab) } label: { Label(CommandID.duplicateTab.title, systemImage: "plus.square.on.square") }.disabled(tab.url == nil)574                            Button(role: .destructive) { AuraMotion.perform(.spring) { model.close(tab) } } label: { Label(L("Close Tab"), systemImage: "xmark") }575                        }576                        .transition(AuraTransition.tabChip(policy))577                        .id(tab.id)578                        .accessibilityElement(children: .combine)579                        .accessibilityLabel(tab.displayTitle)580                        .accessibilityAddTraits(selected ? [.isSelected, .isButton] : .isButton)581                        .accessibilityAction(named: L("Close Tab")) { model.close(tab) }582                    }583                }584                .padding(.horizontal, 10).padding(.vertical, 5)585                .auraAnimation(.spring, value: model.visibleTabs.map(\.id))586            }587            .onChange(of: model.selectedTabID) { _, id in if let id { withAnimation(AuraMotion.animation(.standard, policy: policy)) { proxy.scrollTo(id) } } }588        }589    }590}591592/// iPad sidebar: tabs, AURA surfaces, bookmarks, reading list, history and downloads without leaving the page.593struct PadSidebar: View {594    @Bindable var model: BrowserModel595    let environment: MobileEnvironment596    @State private var section: LibrarySection?597598    var body: some View {599        NavigationStack {600            List {601                Section(model.showsPrivate ? L("Private tabs") : L("Tabs")) {602                    ForEach(model.visibleTabs) { tab in603                        let selected = tab.id == model.selectedTabID604                        Button { AuraMotion.perform(.spring) { model.select(tab) } } label: {605                            HStack {606                                Image(systemName: tab.isSearchPage ? "magnifyingglass" : "globe").foregroundStyle(selected ? AnyShapeStyle(Aura.Palette.accent) : AnyShapeStyle(.secondary)).frame(width: 22)607                                Text(tab.displayTitle).lineLimit(1).foregroundStyle(.primary).fontWeight(selected ? .medium : .regular)608                                Spacer()609                            }610                            .contentShape(Rectangle())611                        }612                        .buttonStyle(AuraPressStyle(scale: 0.98))613                        .listRowBackground(RoundedRectangle(cornerRadius: Aura.Radius.m, style: .continuous)614                            .fill(selected ? AnyShapeStyle((tab.isPrivate ? Aura.Palette.violet : Aura.Palette.accent).opacity(0.16)) : AnyShapeStyle(Color.clear)).padding(.horizontal, 6))615                        .hoverEffect(.highlight)616                        .swipeActions { Button(role: .destructive) { model.close(tab) } label: { Label(L("Close"), systemImage: "xmark") } }617                    }618                    Button { model.newTab() } label: { Label(L("New Tab"), systemImage: "plus") }619                    Toggle(isOn: Binding(get: { model.showsPrivate }, set: { model.setPrivate($0) })) { Label(L("Private Browsing"), systemImage: "eyeglasses") }620                }621                Section("AURA") {622                    ForEach([CommandID.showConstellation, .showFlow, .showCanvas, .showPortal, .toggleFocusMode], id: \.self) { command in623                        Button { model.perform(command) } label: {624                            Label { Text(OrbitCatalog.shortTitle(command)).foregroundStyle(.primary) } icon: { Image(systemName: OrbitCatalog.symbol(command)).foregroundStyle(Aura.gradient) }625                        }626                        .disabled(!model.isEnabled(command))627                        .hoverEffect(.highlight)628                        .accessibilityIdentifier("sidebar-" + command.rawValue)629                    }630                }631                Section(L("Library")) {632                    ForEach(LibrarySection.allCases) { item in633                        NavigationLink(value: item) { Label(item.title, systemImage: item.symbol) }634                    }635                }636                Section {637                    Button { model.showsSettings = true } label: { Label(L("Settings…"), systemImage: "gearshape") }638                }639            }640            .listStyle(.sidebar)641            .scrollContentBackground(.hidden)642            .background(Aura.Palette.chrome.ignoresSafeArea())643            .auraAnimation(.spring, value: model.visibleTabs.map(\.id))644            .navigationTitle("SP Browser")645            .navigationDestination(for: LibrarySection.self) { item in646                LibraryContent(section: item, model: model, environment: environment).navigationTitle(item.title).navigationBarTitleDisplayMode(.inline)647            }648        }649    }650}651
Files main
Menu

Theme