Files
TUIkit/Sources/TUIkitStyling/SemanticColor.swift
T
phranck ce850e1b29 Refactor: Extract TUIkitStyling and TUIkitImage modules
- 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
2026-02-14 03:14:14 +01:00

71 lines
2.0 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 🖥 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
}
}
}