Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Browser9// File : SPBrowser/Features/Aura/AuraOverlays.swift10// Module : SPBrowser11// Repository : https://git.spboucher.ai/sp-browser12// Created : 2026-11-1913// Last Modified : 2026-11-1914//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : None specified (no license file in this repository)80// Maintainer : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import SwiftUI8889/// Hosts the full-window AURA surfaces of a Mac browser window and their transitions.90struct AuraOverlayHost: View {91 @Bindable var state: BrowserWindowState92 let environment: AppEnvironment93 @Environment(\.auraPolicy) private var policy9495 var body: some View {96 ZStack {97 switch state.auraOverlay {98 case .none: EmptyView()99 case .constellation:100 ConstellationView(items: state.constellationItems, selectedID: state.selectedTabID, isPrivate: state.isPrivate,101 thumbnail: { state.tab(id: $0)?.thumbnail }, icon: { state.tab(id: $0)?.favicon },102 onOpen: state.constellationOpen, onClose: state.constellationClose, onGroup: state.constellationGroup,103 onMove: state.constellationMove, onNewTab: { state.dismissAura(); state.perform(.newTab) }, onDismiss: state.dismissAura)104 .transition(policy.allowsSpatial ? .opacity.combined(with: .scale(scale: 1.06)) : .opacity)105 case .flow:106 sheet(maxWidth: 1180) {107 FlowMapView(trail: state.flowTrail, currentNodeID: state.flowCursor, isPrivate: state.isPrivate, isRecording: environment.settings.flowEnabled,108 onOpen: state.flowOpen, onDeleteJourney: state.flowForget, onDismiss: state.dismissAura)109 }110 case .canvas:111 sheet(maxWidth: 1400, inset: 26) { CanvasBoardView(controller: state.canvas, host: state.canvasHost) }112 case .portal:113 let _ = environment.services.libraryRevision114 sheet(maxWidth: 720) {115 PortalView(devices: environment.services.portalDevices, handoffs: state.isPrivate ? [] : environment.services.pendingHandoffs, host: state.portalHost)116 }117 }118 }119 .onExitCommand { state.dismissAura() }120 }121122 private func sheet<Content: View>(maxWidth: CGFloat, inset: CGFloat = 44, @ViewBuilder content: () -> Content) -> some View {123 ZStack {124 Color.black.opacity(0.34).ignoresSafeArea().onTapGesture { state.dismissAura() }125 .accessibilityLabel(L("Close")).accessibilityAddTraits(.isButton)126 .transition(.opacity)127 content()128 .clipShape(RoundedRectangle(cornerRadius: Aura.Radius.xl, style: .continuous))129 .auraSurface(.overlay, radius: Aura.Radius.xl)130 .frame(maxWidth: maxWidth)131 .padding(.horizontal, inset).padding(.top, inset + 14).padding(.bottom, inset)132 .transition(AuraTransition.depth(policy, anchor: .center))133 .accessibilityAddTraits(.isModal)134 }135 }136}137138/// Command Orbit on the Mac: a ring that opens around the pointer, kept inside the window.139struct OrbitOverlay: View {140 @Bindable var state: BrowserWindowState141 let environment: AppEnvironment142143 var body: some View {144 GeometryReader { proxy in145 let side: CGFloat = 340146 let anchor = state.orbitAnchor ?? CGPoint(x: proxy.size.width / 2, y: proxy.size.height / 2)147 let center = CGPoint(x: anchor.x.clamped(side / 2 + 8, max(proxy.size.width - side / 2 - 8, side / 2 + 8)),148 y: anchor.y.clamped(side / 2 + 8, max(proxy.size.height - side / 2 - 8, side / 2 + 8)))149 ZStack {150 Color.black.opacity(0.10).ignoresSafeArea().onTapGesture { AuraMotion.perform(.quick) { state.orbitVisible = false } }151 .accessibilityLabel(L("Close")).accessibilityAddTraits(.isButton)152 OrbitView(commands: OrbitCatalog.ring(for: state.orbitContext), isEnabled: state.isEnabled,153 shortcut: { $0.shortcut(overrides: environment.settings.shortcutOverrides)?.display ?? "" },154 onRun: state.orbitRun, onType: state.orbitHandOver,155 onDismiss: { AuraMotion.perform(.quick) { state.orbitVisible = false }; state.window?.makeFirstResponder(state.selectedTab?.webView) })156 .position(center)157 }158 }159 .transition(.opacity)160 }161}162163/// Shows the Peek card next to the link it previews, and decides when a hover becomes a peek.164struct PeekLayer: View {165 @Bindable var tab: BrowserTab166 @Bindable var state: BrowserWindowState167 let environment: AppEnvironment168 @State private var overCard = false169 @Environment(\.auraPolicy) private var policy170171 private let cardWidth: CGFloat = 340172173 var body: some View {174 GeometryReader { proxy in175 if let model = state.peek, let link = state.peekLink, state.selectedTabID == tab.id {176 let rect = CGRect(x: link.unitRect.minX * proxy.size.width, y: link.unitRect.minY * proxy.size.height,177 width: link.unitRect.width * proxy.size.width, height: link.unitRect.height * proxy.size.height)178 let x = (rect.midX - cardWidth / 2).clamped(12, max(proxy.size.width - cardWidth - 12, 12))179 let below = rect.midY < proxy.size.height * 0.52180 VStack(spacing: 0) {181 if !below { Spacer(minLength: 0) }182 AuraFloatingPanel(radius: 18, anchor: below ? .top : .bottom) { PeekCard(model: model, actions: state.peekActions, width: cardWidth) }183 .onHover { overCard = $0 }184 .onExitCommand { state.dismissPeek() }185 if below { Spacer(minLength: 0) }186 }187 .frame(width: cardWidth, height: below ? max(proxy.size.height - rect.maxY - 20, 120) : max(rect.minY - 20, 120), alignment: below ? .top : .bottom)188 .offset(x: x, y: below ? rect.maxY + 8 : 12)189 .id(model.id)190 }191 }192 .allowsHitTesting(state.peek != nil)193 // ⌥-hover peeks at once; a plain hover peeks after a pause when the user turned that on.194 .task(id: tab.hovered) {195 let link = tab.hovered196 if let link {197 if link.optionHeld { state.showPeek(link); return }198 if environment.settings.peekOnHover {199 try? await Task.sleep(for: .milliseconds(750))200 if !Task.isCancelled, tab.hovered == link { state.showPeek(link) }201 }202 } else if state.peek != nil {203 // Leaving the link gives the pointer time to reach the card.204 try? await Task.sleep(for: .milliseconds(380))205 if !Task.isCancelled, !overCard, tab.hovered == nil { state.dismissPeek() }206 }207 }208 .onChange(of: overCard) { _, inside in209 if !inside, tab.hovered == nil {210 Task { try? await Task.sleep(for: .milliseconds(300)); if !overCard, tab.hovered == nil { state.dismissPeek() } }211 }212 }213 }214}215216/// Tab Morphing: a new tab's page grows out of the link that opened it, then the veil dissolves to reveal the page.217struct MorphVeil: View {218 let morph: TabMorph219 let title: String220 var onFinished: () -> Void221 @State private var expanded = false222 @State private var faded = false223 @Environment(\.auraPolicy) private var policy224225 var body: some View {226 GeometryReader { proxy in227 let anchor = UnitPoint(x: morph.origin.x.clamped(0, 1), y: morph.origin.y.clamped(0, 1))228 RoundedRectangle(cornerRadius: expanded ? 0 : 26, style: .continuous)229 .fill(Aura.Palette.surface)230 .overlay {231 VStack(spacing: 10) {232 AuraProgressIndicator(progress: nil, style: .ring, thickness: 2).frame(width: 22, height: 22)233 Text(title).font(.callout).foregroundStyle(.secondary).lineLimit(1).padding(.horizontal, 40)234 }235 .opacity(expanded ? 1 : 0)236 }237 .overlay(RoundedRectangle(cornerRadius: expanded ? 0 : 26, style: .continuous).strokeBorder(Aura.horizontalGradient, lineWidth: expanded ? 0 : 2))238 .frame(width: proxy.size.width, height: proxy.size.height)239 .scaleEffect(expanded || !policy.allowsSpatial ? 1 : 0.06, anchor: anchor)240 .opacity(faded ? 0 : 1)241 }242 .allowsHitTesting(false)243 .accessibilityHidden(true)244 .task(id: morph.id) {245 withAnimation(AuraMotion.animation(.expressive, policy: policy)) { expanded = true }246 try? await Task.sleep(for: .milliseconds(policy.allowsSpatial ? 420 : 120))247 withAnimation(AuraMotion.animation(.standard, policy: policy)) { faded = true }248 try? await Task.sleep(for: .milliseconds(280))249 onFinished()250 }251 }252}253