Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Browser9// File : SPBrowser/Shared/Aura/AuraMaterial.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/// AURA Material Engine. A surface is a native system material, a faint AURA tint, a luminous rim and a shadow that90/// depends on elevation. Interactive surfaces react to the pointer (a soft light that follows it) and to touch (they give slightly).91enum AuraLevel: Sendable {92 /// Bars and sidebars that belong to the window.93 case chrome94 /// Cards and panels resting on content.95 case panel96 /// Bars and panels floating over content.97 case floating98 /// Palettes, peeks, modals.99 case overlay100101 var elevation: Aura.Elevation {102 switch self {103 case .chrome: return .flat104 case .panel: return .raised105 case .floating: return .floating106 case .overlay: return .overlay107 }108 }109110 var material: Material {111 switch self {112 case .chrome: return .bar113 case .panel: return .regularMaterial114 case .floating: return .thinMaterial115 case .overlay: return .regularMaterial116 }117 }118}119120struct AuraSurfaceModifier: ViewModifier {121 var level: AuraLevel = .panel122 var radius: CGFloat = Aura.Radius.l123 var tint: Color?124 var isInteractive = false125 /// A glowing AURA rim (focus, selection). Animates in and out.126 var isLuminous = false127128 @Environment(\.auraPolicy) private var policy129 @State private var pointer: CGPoint?130 @State private var pressed = false131132 func body(content: Content) -> some View {133 let shape = RoundedRectangle(cornerRadius: radius, style: .continuous)134 let shadow = level.elevation.shadow135 content136 .background {137 ZStack {138 shape.fill(level.material)139 shape.fill(Aura.Palette.glassTint.opacity(level == .chrome ? 0.35 : 0.5))140 if let tint { shape.fill(tint.opacity(0.10)) }141 if isInteractive, let pointer {142 // Pointer light: one radial gradient that follows the pointer, drawn only while it is over the surface.143 Circle().fill(RadialGradient(colors: [Color.white.opacity(0.11), .clear], center: .center, startRadius: 0, endRadius: 150))144 .frame(width: 300, height: 300).position(pointer).clipShape(shape).allowsHitTesting(false)145 }146 }147 }148 .overlay {149 shape.strokeBorder(LinearGradient(colors: [Aura.Palette.rimLight, Aura.Palette.rimShade], startPoint: .top, endPoint: .bottom), lineWidth: 1)150 .opacity(level == .chrome ? 0.5 : 1)151 }152 .overlay {153 if isLuminous { shape.strokeBorder(Aura.horizontalGradient, lineWidth: 1.5).transition(.opacity) }154 }155 .shadow(color: .black.opacity(shadow.opacity + (isLuminous ? 0.04 : 0)), radius: shadow.radius, y: shadow.y)156 .shadow(color: isLuminous ? Aura.Palette.violet.opacity(0.28) : .clear, radius: 14)157 .scaleEffect(pressed && policy.allowsSpatial ? 0.985 : 1)158 .animation(AuraMotion.animation(.quick, policy: policy), value: isLuminous)159 .animation(AuraMotion.animation(.interactive, policy: policy), value: pressed)160 .modifier(PointerTracking(isEnabled: isInteractive, pointer: $pointer, pressed: $pressed))161 }162}163164/// Tracks the pointer (Mac, iPad with trackpad) over an interactive surface.165private struct PointerTracking: ViewModifier {166 let isEnabled: Bool167 @Binding var pointer: CGPoint?168 @Binding var pressed: Bool169170 func body(content: Content) -> some View {171 if isEnabled {172 content.onContinuousHover(coordinateSpace: .local) { phase in173 switch phase {174 case .active(let location): pointer = location175 case .ended: pointer = nil176 }177 }178 } else {179 content180 }181 }182}183184extension View {185 /// Gives the view an AURA surface: material, tint, luminous rim and elevation shadow.186 func auraSurface(_ level: AuraLevel = .panel, radius: CGFloat = Aura.Radius.l, tint: Color? = nil, interactive: Bool = false, luminous: Bool = false) -> some View {187 modifier(AuraSurfaceModifier(level: level, radius: radius, tint: tint, isInteractive: interactive, isLuminous: luminous))188 }189190 /// The field look shared by the address bar, the search fields and the palette input.191 func auraField(focused: Bool, radius: CGFloat = Aura.Radius.m, tint: Color? = nil) -> some View {192 modifier(AuraFieldModifier(focused: focused, radius: radius, tint: tint))193 }194}195196struct AuraFieldModifier: ViewModifier {197 let focused: Bool198 var radius: CGFloat = Aura.Radius.m199 var tint: Color?200 @Environment(\.auraPolicy) private var policy201202 func body(content: Content) -> some View {203 let shape = RoundedRectangle(cornerRadius: radius, style: .continuous)204 content205 .background(shape.fill(Aura.Palette.field))206 .overlay(shape.strokeBorder(tint ?? Aura.Palette.hairline, lineWidth: 1).opacity(focused ? 0 : 1))207 .overlay(shape.strokeBorder(Aura.horizontalGradient, lineWidth: 1.5).opacity(focused ? 1 : 0))208 .shadow(color: Aura.Palette.violet.opacity(focused ? 0.22 : 0), radius: focused ? 12 : 0)209 .shadow(color: .black.opacity(focused ? 0.10 : 0.04), radius: focused ? 14 : 5, y: focused ? 5 : 2)210 .animation(AuraMotion.animation(.standard, policy: policy), value: focused)211 }212}213214/// A surface as a container, for call sites that prefer a wrapper to a modifier.215struct AuraSurface<Content: View>: View {216 var level: AuraLevel = .panel217 var radius: CGFloat = Aura.Radius.l218 var tint: Color?219 var interactive = false220 @ViewBuilder var content: () -> Content221222 var body: some View { content().auraSurface(level, radius: radius, tint: tint, interactive: interactive) }223}224225/// A panel floating over content, with its entry transition and an accessibility container.226struct AuraFloatingPanel<Content: View>: View {227 var radius: CGFloat = Aura.Radius.xl228 var tint: Color?229 var anchor: UnitPoint = .top230 @ViewBuilder var content: () -> Content231 @Environment(\.auraPolicy) private var policy232233 var body: some View {234 content()235 .clipShape(RoundedRectangle(cornerRadius: radius, style: .continuous))236 .auraSurface(.overlay, radius: radius, tint: tint)237 .transition(AuraTransition.depth(policy, anchor: anchor))238 .accessibilityElement(children: .contain)239 }240}241