Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Apps/GlassStudio/Kit/Model/PreviewConfiguration.swift8// Module : GlassStudio9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344/// What surrounds a component in the preview canvas.45public enum PreviewBackdrop: String, CaseIterable, Codable, Sendable, Identifiable {46 /// The theme's background colour.47 case themed48 case white49 case black50 /// A procedurally drawn colourful scene standing in for a photograph (no image file is bundled).51 case scene52 /// A high-contrast checkerboard, the hardest case for legibility over glass.53 case checkerboard5455 public var id: String { rawValue }56}5758/// The conditions a preview is shown in. "Simulated" settings affect only the preview subtree; they never59/// change the device configuration, and the Studio labels them as simulations.60public struct PreviewConfiguration: Equatable, Codable, Sendable {61 public var themeID: GlassThemeID = "system"62 public var appearance: GlassAppearance = .system63 public var backdrop: PreviewBackdrop = .themed64 public var density: GlassDensity?65 /// Index into ``textSizes``; `nil` follows the system.66 public var textSizeIndex: Int?67 public var simulateReduceTransparency = false68 public var simulateReduceMotion = false69 public var rightToLeft = false7071 public init() {}7273 public static let textSizes: [DynamicTypeSize] = [.xSmall, .small, .medium, .large, .xLarge, .xxLarge, .xxxLarge, .accessibility1, .accessibility2, .accessibility3, .accessibility4, .accessibility5]7475 public var dynamicTypeSize: DynamicTypeSize? {76 guard let textSizeIndex, Self.textSizes.indices.contains(textSizeIndex) else { return nil }77 return Self.textSizes[textSizeIndex]78 }7980 public var colorScheme: ColorScheme? {81 switch appearance {82 case .system: nil83 case .light: .light84 case .dark: .dark85 }86 }8788 /// The theme to apply: the chosen theme with the preview's density, if one is set.89 public func theme(from base: GlassTheme) -> GlassTheme {90 var theme = base91 if let density { theme.density = density }92 return theme93 }9495 public var hasSimulations: Bool {96 simulateReduceMotion || simulateReduceTransparency || textSizeIndex != nil || rightToLeft || appearance != .system97 }98}99