Repository Public
1// SP Notes Core2// File: Sources/SPNotesDesign/NVElevation.swift3// Description: Note Visual System 2.0 elevation: card (hairline + 1 px shadow), pop (16/40 shadow), glass (system material,4// 60–72 % surface, hairline), as view modifiers.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SwiftUI910/// The three elevation levels.11public enum NVElevation: String, Sendable, Hashable, CaseIterable {12 /// Hairline border and a 1 px shadow.13 case card14 /// Floating surfaces (menus, popovers): shadow offset 16, blur 40.15 case pop16 /// Translucent chrome: system material under a 66 % surface, hairline border.17 case glass1819 /// Opacity of the surface colour laid over the material of `glass` (specification: 60–72 %).20 public static let glassSurfaceOpacity: Double = 0.6621}2223/// Background, border and shadow of an elevation level.24public struct NVElevationModifier: ViewModifier {25 let level: NVElevation26 let radius: CGFloat27 @Environment(\.accessibilityReduceTransparency) private var reduceTransparency28 @Environment(\.colorScheme) private var scheme2930 public init(_ level: NVElevation, radius: CGFloat) {31 self.level = level32 self.radius = radius33 }3435 public func body(content: Content) -> some View {36 let shape = NVRadius.shape(radius)37 switch level {38 case .card:39 content40 .background(NVColor.bgElevated, in: shape)41 .overlay(shape.strokeBorder(NVColor.line, lineWidth: 1))42 .shadow(color: .black.opacity(scheme == .dark ? 0.30 : 0.06), radius: 0.5, x: 0, y: 1)43 case .pop:44 content45 .background(NVColor.bgElevated, in: shape)46 .overlay(shape.strokeBorder(NVColor.line, lineWidth: 1))47 .shadow(color: .black.opacity(scheme == .dark ? 0.50 : 0.16), radius: 20, x: 0, y: 16)48 case .glass:49 content50 .background {51 if reduceTransparency {52 shape.fill(NVColor.bgElevated)53 } else {54 shape.fill(.ultraThinMaterial)55 shape.fill(NVColor.bgElevated.opacity(NVElevation.glassSurfaceOpacity))56 }57 }58 .overlay(shape.strokeBorder(NVColor.line, lineWidth: 1))59 }60 }61}6263extension View {64 /// Applies an elevation level with the given corner radius.65 public func nvElevation(_ level: NVElevation, radius: CGFloat = NVRadius.lg) -> some View {66 modifier(NVElevationModifier(level, radius: radius))67 }6869 /// Card surface: elevated background, hairline, 1 px shadow.70 public func nvCard(radius: CGFloat = NVRadius.lg) -> some View { nvElevation(.card, radius: radius) }7172 /// Floating surface (menu, popover).73 public func nvPop(radius: CGFloat = NVRadius.lg) -> some View { nvElevation(.pop, radius: radius) }7475 /// Translucent chrome; opaque under Reduce Transparency.76 public func nvGlass(radius: CGFloat = NVRadius.lg) -> some View { nvElevation(.glass, radius: radius) }77}78