Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Apps/GlassStudio/Kit/Playground/PlaygroundTemplate.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 Foundation42import SPGlassKit4344/// Starting points for a composition. A template lists component identifiers; the ones a catalogue does not45/// offer for composition are left out, so a template is always valid for the catalogue it is built with.46public enum PlaygroundTemplate: String, CaseIterable, Identifiable, Sendable {47 case realEstate, dashboard, messaging, audioPlayer, map, form4849 public var id: String { rawValue }5051 public var title: String {52 switch self {53 case .realEstate: L("Property listing")54 case .dashboard: L("Dashboard")55 case .messaging: L("Messaging")56 case .audioPlayer: L("Audio player")57 case .map: L("Map")58 case .form: L("Form")59 }60 }6162 public var symbol: String {63 switch self {64 case .realEstate: "building.2"65 case .dashboard: "chart.bar"66 case .messaging: "bubble.left.and.bubble.right"67 case .audioPlayer: "waveform"68 case .map: "map"69 case .form: "list.bullet.rectangle"70 }71 }7273 private indirect enum Outline {74 case stack(PlaygroundAxis, GlassSpacingStep, PlaygroundAlignment, [Outline])75 case component(String, [String: InspectorValue])76 }7778 private var outline: Outline {79 switch self {80 case .realEstate:81 .stack(.vertical, .md, .leading, [82 .component("glass-card", [:]),83 .stack(.horizontal, .xs, .center, [.component("glass-badge", [:]), .component("glass-badge", [:])]),84 .component("glass-metric-card", [:]),85 .stack(.horizontal, .sm, .center, [86 .component("glass-button", ["title": .text("Book a visit"), "symbol": .text("calendar"), "variant": .choice("prominent")]),87 .component("glass-icon-button", ["symbol": .text("heart"), "label": .text("Save")]),88 ]),89 ])90 case .dashboard:91 .stack(.vertical, .md, .leading, [92 .stack(.horizontal, .sm, .center, [.component("glass-metric-card", [:]), .component("glass-metric-card", [:])]),93 .component("glass-chart", [:]),94 .component("glass-progress", [:]),95 .component("glass-banner", [:]),96 ])97 case .messaging:98 .stack(.vertical, .sm, .leading, [99 .component("glass-chat-bubble", [:]),100 .component("glass-chat-bubble", [:]),101 .component("glass-thinking-indicator", [:]),102 .component("glass-prompt-bar", [:]),103 ])104 case .audioPlayer:105 .stack(.vertical, .lg, .center, [106 .component("glass-waveform", [:]),107 .component("glass-audio-player", [:]),108 .component("glass-volume-control", [:]),109 ])110 case .map:111 .stack(.depth, .md, .trailing, [112 .stack(.vertical, .sm, .trailing, [113 .component("glass-map-pin", [:]),114 .component("glass-map-controls", [:]),115 .stack(.horizontal, .xs, .center, [.component("glass-compass", [:]), .component("glass-location-button", [:])]),116 ]),117 ])118 case .form:119 .stack(.vertical, .md, .leading, [120 .component("glass-text-field", [:]),121 .component("glass-secure-field", [:]),122 .component("glass-toggle", [:]),123 .component("glass-button", ["title": .text("Create account"), "symbol": .text(""), "variant": .choice("prominent")]),124 ])125 }126 }127128 @MainActor129 public func document(catalog: ComponentCatalog) -> PlaygroundDocument {130 let known = catalog.composableIDs131 func build(_ outline: Outline) -> PlaygroundNode? {132 switch outline {133 case .component(let id, let values):134 return known.contains(id) ? .component(id, values) : nil135 case .stack(let axis, let spacing, let alignment, let children):136 return .stack(axis, spacing: spacing, alignment: alignment, children.compactMap(build))137 }138 }139 return PlaygroundDocument(name: title, root: build(outline) ?? .stack())140 }141}142