mirror of
https://github.com/phranck/TUIkit.git
synced 2026-05-21 09:50:35 +00:00
ce850e1b29
- Extract 12 pure type definitions (Color, Palette, Appearance, BorderStyle, etc.) into TUIkitStyling module with no dependencies - Extract 3 image processing files (RGBAImage, ImageLoader, ASCIIConverter) into TUIkitImage module (deps: CSTBImage, TUIkitStyling) - Split 6 mixed files into type definitions (TUIkitStyling) and environment glue (TUIkit/Styling/) - Decouple ThemeManager from AppState via renderTrigger closure - Decouple ASCIIConverter from ANSIRenderer via local ANSIEscape constants - Add @_exported imports in Exports.swift for backward compatibility - All 1064 tests pass, no breaking API changes
71 lines
2.0 KiB
Swift
71 lines
2.0 KiB
Swift
// 🖥️ TUIKit — Terminal UI Kit for Swift
|
||
// SemanticColor.swift
|
||
//
|
||
// Created by LAYERED.work
|
||
// License: MIT
|
||
|
||
/// A token that names a palette property.
|
||
///
|
||
/// `SemanticColor` is the value stored inside `Color.ColorValue.semantic`.
|
||
/// At render time ``Color/resolve(with:)`` maps the token to the concrete
|
||
/// ``Color`` returned by the current ``Palette``.
|
||
///
|
||
/// This enables views to declare palette-relative colors in their `body`
|
||
/// without needing a ``RenderContext``:
|
||
///
|
||
/// ```swift
|
||
/// Text("Hello").foregroundStyle(.palette.accent)
|
||
/// ```
|
||
public enum SemanticColor: String, Sendable, Equatable {
|
||
// Background
|
||
case background
|
||
case statusBarBackground
|
||
case appHeaderBackground
|
||
case overlayBackground
|
||
|
||
// Foreground
|
||
case foreground
|
||
case foregroundSecondary
|
||
case foregroundTertiary
|
||
case foregroundQuaternary
|
||
|
||
// Accent
|
||
case accent
|
||
|
||
// Status
|
||
case success
|
||
case warning
|
||
case error
|
||
case info
|
||
|
||
// UI Elements
|
||
case border
|
||
}
|
||
|
||
// MARK: - Color Resolution
|
||
|
||
extension SemanticColor {
|
||
/// Resolves this token to a concrete color using the given palette.
|
||
///
|
||
/// - Parameter palette: The palette to read from.
|
||
/// - Returns: The concrete ``Color`` from the palette.
|
||
func resolve(with palette: any Palette) -> Color {
|
||
switch self {
|
||
case .background: palette.background
|
||
case .statusBarBackground: palette.statusBarBackground
|
||
case .appHeaderBackground: palette.appHeaderBackground
|
||
case .overlayBackground: palette.overlayBackground
|
||
case .foreground: palette.foreground
|
||
case .foregroundSecondary: palette.foregroundSecondary
|
||
case .foregroundTertiary: palette.foregroundTertiary
|
||
case .foregroundQuaternary: palette.foregroundQuaternary
|
||
case .accent: palette.accent
|
||
case .success: palette.success
|
||
case .warning: palette.warning
|
||
case .error: palette.error
|
||
case .info: palette.info
|
||
case .border: palette.border
|
||
}
|
||
}
|
||
}
|