-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeConfig.swift
More file actions
62 lines (51 loc) · 2.04 KB
/
ThemeConfig.swift
File metadata and controls
62 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Foundation
/// Root structure of a theme.json file.
nonisolated public struct ThemeFile: Sendable, Codable, Equatable {
/// Style token definitions (colors, gradients, shadows).
public let styles: ThemeConfig
/// Generation configuration (output path, etc.).
public let config: GenerationConfig?
/// Configuration for code generation.
nonisolated public struct GenerationConfig: Sendable, Codable, Equatable {
/// Relative path from the generation root where generated files should be written.
public let outputPath: String
/// When true, generates a Theme+Preview.swift file containing a SwiftUI preview view.
public let shouldGeneratePreview: Bool?
nonisolated public init(outputPath: String, shouldGeneratePreview: Bool? = nil) {
self.outputPath = outputPath
self.shouldGeneratePreview = shouldGeneratePreview
}
}
nonisolated public init(styles: ThemeConfig, config: GenerationConfig? = nil) {
self.styles = styles
self.config = config
}
/// The resolved output path, defaulting to "." if no config is present.
nonisolated public var resolvedOutputPath: String {
config?.outputPath ?? "."
}
/// Whether to generate a preview file, defaulting to false.
nonisolated public var shouldGeneratePreview: Bool {
config?.shouldGeneratePreview ?? false
}
}
nonisolated public struct ThemeConfig: Sendable, Codable, Equatable {
public let colors: [ThemeToken]?
public let gradients: [ThemeToken]?
public let shadows: [ThemeToken]?
nonisolated public init(
colors: [ThemeToken]? = nil,
gradients: [ThemeToken]? = nil,
shadows: [ThemeToken]? = nil
) {
self.colors = colors
self.gradients = gradients
self.shadows = shadows
}
nonisolated public var categories: [ThemeCategory] {
ThemeCategory.allCases.filter { category in
let tokens = category.tokens(from: self)
return !tokens.isEmpty
}
}
}