diff --git a/Sources/FigmaGen/Generators/Tokens/Providers/BoxShadowTokensContext/DefaultBoxShadowTokensContextProvider.swift b/Sources/FigmaGen/Generators/Tokens/Providers/BoxShadowTokensContext/DefaultBoxShadowTokensContextProvider.swift index eb8a6a9..4e0074d 100644 --- a/Sources/FigmaGen/Generators/Tokens/Providers/BoxShadowTokensContext/DefaultBoxShadowTokensContextProvider.swift +++ b/Sources/FigmaGen/Generators/Tokens/Providers/BoxShadowTokensContext/DefaultBoxShadowTokensContextProvider.swift @@ -23,7 +23,7 @@ final class DefaultBoxShadowTokensContextProvider: BoxShadowTokensContextProvide return nil } - guard let nightTokenValue = tokenValues.night.first(where: { $0.name == dayTokenValue.name }) else { + guard let nightTokenValue = tokenValues.hhNight.first(where: { $0.name == dayTokenValue.name }) else { throw BoxShadowTokensContextProviderError(code: .nightValueNotFound(tokenName: dayTokenValue.name)) } @@ -41,7 +41,7 @@ final class DefaultBoxShadowTokensContextProvider: BoxShadowTokensContextProvide // MARK: - func fetchBoxShadowTokensContext(from tokenValues: TokenValues) throws -> [BoxShadowToken] { - try tokenValues.day + try tokenValues.hhDay .compactMap { try makeBoxShadowToken(from: $0, tokenValues: tokenValues) } .sorted { $0.path.joined() < $1.path.joined() } } diff --git a/Sources/FigmaGen/Generators/Tokens/Providers/ColorTokensContext/DefaultColorTokensContextProvider.swift b/Sources/FigmaGen/Generators/Tokens/Providers/ColorTokensContext/DefaultColorTokensContextProvider.swift index 0957b6c..4765b83 100644 --- a/Sources/FigmaGen/Generators/Tokens/Providers/ColorTokensContext/DefaultColorTokensContextProvider.swift +++ b/Sources/FigmaGen/Generators/Tokens/Providers/ColorTokensContext/DefaultColorTokensContextProvider.swift @@ -23,7 +23,7 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider { fallbackValue: String, tokenValues: TokenValues ) throws -> String { - guard let nightToken = tokenValues.night.first(where: { $0.name == tokenName }) else { + guard let nightToken = tokenValues.hhNight.first(where: { $0.name == tokenName }) else { fallbackWarning(tokenName: tokenName) return fallbackValue } @@ -45,7 +45,7 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider { fallbackRefence: String, tokenValues: TokenValues ) throws -> String { - guard let nightToken = tokenValues.night.first(where: { $0.name == tokenName }) else { + guard let nightToken = tokenValues.hhNight.first(where: { $0.name == tokenName }) else { fallbackWarning(tokenName: tokenName) return fallbackRefence } @@ -55,7 +55,7 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider { return fallbackRefence } - return try tokensResolver.resolveBaseReference(nightValue, tokenValues: tokenValues.night) + return try tokensResolver.resolveBaseReference(nightValue, tokenValues: tokenValues.hhNight) } private func makeColorToken( @@ -72,7 +72,7 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider { let dayReference = try tokensResolver.resolveBaseReference( dayValue, - tokenValues: tokenValues.day + tokenValues: tokenValues.hhDay ) let nightReference = try resolveNightReference( @@ -132,7 +132,7 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider { // MARK: - func fetchColorTokensContext(from tokenValues: TokenValues) throws -> [String: Any] { - let colors: [ColorToken] = try tokenValues.day.compactMap { (token: TokenValue) in + let colors: [ColorToken] = try tokenValues.hhDay.compactMap { (token: TokenValue) in guard case .color(let dayValue) = token.type else { return nil } diff --git a/Sources/FigmaGen/Models/Token/TokenValues.swift b/Sources/FigmaGen/Models/Token/TokenValues.swift index 1b60d71..39ab92d 100644 --- a/Sources/FigmaGen/Models/Token/TokenValues.swift +++ b/Sources/FigmaGen/Models/Token/TokenValues.swift @@ -1,6 +1,6 @@ import Foundation -struct TokenValues: Codable, Hashable { +struct TokenValues: Hashable { // MARK: - Instance Properties @@ -8,8 +8,9 @@ struct TokenValues: Codable, Hashable { let semantic: [TokenValue] let colors: [TokenValue] let typography: [TokenValue] - let day: [TokenValue] - let night: [TokenValue] + let hhDay: [TokenValue] + let hhNight: [TokenValue] + let zpDay: [TokenValue] // MARK: - Instance Properties @@ -18,13 +19,33 @@ struct TokenValues: Codable, Hashable { func getThemeTokenValues(theme: Theme) -> [TokenValue] { switch theme { case .day: - return [day, core, semantic, colors, typography].flatMap { $0 } + return [hhDay, core, semantic, colors, typography].flatMap { $0 } case .night: - return [night, core, semantic, colors, typography].flatMap { $0 } + return [hhNight, core, semantic, colors, typography].flatMap { $0 } case .undefined: - return [core, semantic, colors, typography, day, night].flatMap { $0 } + return [core, semantic, colors, typography, hhDay, hhNight].flatMap { $0 } } } } + +// MARK: - Codable + +extension TokenValues: Codable { + + // MARK: - Nested Types + + private enum CodingKeys: String, CodingKey { + + // MARK: - Enumeration Cases + + case core + case semantic + case colors + case typography + case hhDay = "hh-day" + case hhNight = "hh-night" + case zpDay = "zp-day" + } +} diff --git a/Tests/FigmaGenTests/TokensResolverTests.swift b/Tests/FigmaGenTests/TokensResolverTests.swift index 7b2903f..8957fbd 100644 --- a/Tests/FigmaGenTests/TokensResolverTests.swift +++ b/Tests/FigmaGenTests/TokensResolverTests.swift @@ -20,8 +20,9 @@ final class TokensResolverTests: XCTestCase { semantic: [], colors: [], typography: [], - day: [], - night: [] + hhDay: [], + hhNight: [], + zpDay: [] ) let value = "{core.space.1-x} + {core.space.1-x} / 2" @@ -64,8 +65,9 @@ final class TokensResolverTests: XCTestCase { TokenValue(type: .core(value: "#ffffff"), name: "color.base.white") ], typography: [], - day: [], - night: [] + hhDay: [], + hhNight: [], + zpDay: [] ) let value = "rgba({color.base.white}, {semantic.opacity.disabled})" @@ -97,8 +99,9 @@ final class TokensResolverTests: XCTestCase { TokenValue(type: .color(value: "#d64030"), name: "color.base.red.50") ], typography: [], - day: [], - night: [] + hhDay: [], + hhNight: [], + zpDay: [] ) let firstColor = "rgba({color.base.red.50}, {semantic.opacity.transparent})" @@ -187,8 +190,9 @@ final class TokensResolverTests: XCTestCase { TokenValue(type: .color(value: "#111"), name: "color.base.gray.5") ], typography: [], - day: [], - night: [] + hhDay: [], + hhNight: [], + zpDay: [] ) let value1 = "rgba({color.base.white}, {semantic.opacity.disabled})" @@ -221,17 +225,18 @@ final class TokensResolverTests: XCTestCase { TokenValue(type: .color(value: "#000000"), name: "color.base.black") ], typography: [], - day: [], - night: [ + hhDay: [], + hhNight: [ TokenValue(type: .color(value: "{color.base.black}"), name: "color.background.primary"), TokenValue(type: .color(value: "{color.background.primary}"), name: "color.background.primary.nested") - ] + ], + zpDay: [] ) let value = "{color.background.primary.nested}" let expectedBaseReference = "{color.base.black}" - let actualBaseReference = try tokensResolver.resolveBaseReference(value, tokenValues: tokenValues.night) + let actualBaseReference = try tokensResolver.resolveBaseReference(value, tokenValues: tokenValues.hhNight) XCTAssertEqual(actualBaseReference, expectedBaseReference) } @@ -248,17 +253,18 @@ final class TokensResolverTests: XCTestCase { TokenValue(type: .color(value: "#000000"), name: "color.base.black") ], typography: [], - day: [], - night: [ + hhDay: [], + hhNight: [ TokenValue(type: .color(value: "{color.base.black}"), name: "color.background.primary"), TokenValue(type: .color(value: "{color.background.primary}"), name: "color.background.primary.nested") - ] + ], + zpDay: [] ) let value = "rgba( {color.background.primary.nested}, {semantic.opacity.disabled})" let expectedBaseReference = "rgba( {color.base.black}, {semantic.opacity.disabled})" - let actualBaseReference = try tokensResolver.resolveBaseReference(value, tokenValues: tokenValues.night) + let actualBaseReference = try tokensResolver.resolveBaseReference(value, tokenValues: tokenValues.hhNight) XCTAssertEqual(actualBaseReference, expectedBaseReference) } @@ -273,8 +279,9 @@ extension TokenValues { semantic: [], colors: [], typography: [], - day: [], - night: [] + hhDay: [], + hhNight: [], + zpDay: [] ) } #endif