308 lines
13 KiB
Swift
308 lines
13 KiB
Swift
//
|
|
// CLGlobalTokens.swift
|
|
// Crush
|
|
//
|
|
// Created by Leon on 2025/8/14.
|
|
//
|
|
|
|
enum CLEnumGlobalToken: String, CaseIterable {
|
|
init?(caseName: String) {
|
|
self = CLEnumGlobalToken.allCases.first(where: { "\($0)" == caseName }) ?? .glo_color_orange_0
|
|
}
|
|
|
|
case glo_color_orange_0 = "glo.color.orange.0"
|
|
case glo_color_orange_10 = "glo.color.orange.10"
|
|
case glo_color_orange_20 = "glo.color.orange.20"
|
|
case glo_color_orange_30 = "glo.color.orange.30"
|
|
case glo_color_orange_40 = "glo.color.orange.40"
|
|
case glo_color_orange_50 = "glo.color.orange.50"
|
|
case glo_color_orange_60 = "glo.color.orange.60"
|
|
case glo_color_orange_70 = "glo.color.orange.70"
|
|
case glo_color_orange_80 = "glo.color.orange.80"
|
|
case glo_color_orange_90 = "glo.color.orange.90"
|
|
case glo_color_yellow_0 = "glo.color.yellow.0"
|
|
case glo_color_yellow_10 = "glo.color.yellow.10"
|
|
case glo_color_yellow_20 = "glo.color.yellow.20"
|
|
case glo_color_yellow_30 = "glo.color.yellow.30"
|
|
case glo_color_yellow_40 = "glo.color.yellow.40"
|
|
case glo_color_yellow_50 = "glo.color.yellow.50"
|
|
case glo_color_yellow_60 = "glo.color.yellow.60"
|
|
case glo_color_yellow_70 = "glo.color.yellow.70"
|
|
case glo_color_yellow_80 = "glo.color.yellow.80"
|
|
case glo_color_yellow_90 = "glo.color.yellow.90"
|
|
case glo_color_grass_0 = "glo.color.grass.0"
|
|
case glo_color_grass_10 = "glo.color.grass.10"
|
|
case glo_color_grass_20 = "glo.color.grass.20"
|
|
case glo_color_grass_30 = "glo.color.grass.30"
|
|
case glo_color_grass_40 = "glo.color.grass.40"
|
|
case glo_color_grass_50 = "glo.color.grass.50"
|
|
case glo_color_grass_60 = "glo.color.grass.60"
|
|
case glo_color_grass_70 = "glo.color.grass.70"
|
|
case glo_color_grass_80 = "glo.color.grass.80"
|
|
case glo_color_grass_90 = "glo.color.grass.90"
|
|
case glo_color_green_0 = "glo.color.green.0"
|
|
case glo_color_green_10 = "glo.color.green.10"
|
|
case glo_color_green_20 = "glo.color.green.20"
|
|
case glo_color_green_30 = "glo.color.green.30"
|
|
case glo_color_green_40 = "glo.color.green.40"
|
|
case glo_color_green_50 = "glo.color.green.50"
|
|
case glo_color_green_60 = "glo.color.green.60"
|
|
case glo_color_green_70 = "glo.color.green.70"
|
|
case glo_color_green_80 = "glo.color.green.80"
|
|
case glo_color_green_90 = "glo.color.green.90"
|
|
case glo_color_mint_0 = "glo.color.mint.0"
|
|
case glo_color_mint_10 = "glo.color.mint.10"
|
|
case glo_color_mint_20 = "glo.color.mint.20"
|
|
case glo_color_mint_30 = "glo.color.mint.30"
|
|
case glo_color_mint_40 = "glo.color.mint.40"
|
|
case glo_color_mint_50 = "glo.color.mint.50"
|
|
case glo_color_mint_60 = "glo.color.mint.60"
|
|
case glo_color_mint_70 = "glo.color.mint.70"
|
|
case glo_color_mint_80 = "glo.color.mint.80"
|
|
case glo_color_mint_90 = "glo.color.mint.90"
|
|
case glo_color_sky_0 = "glo.color.sky.0"
|
|
case glo_color_sky_10 = "glo.color.sky.10"
|
|
case glo_color_sky_20 = "glo.color.sky.20"
|
|
case glo_color_sky_30 = "glo.color.sky.30"
|
|
case glo_color_sky_40 = "glo.color.sky.40"
|
|
case glo_color_sky_50 = "glo.color.sky.50"
|
|
case glo_color_sky_60 = "glo.color.sky.60"
|
|
case glo_color_sky_70 = "glo.color.sky.70"
|
|
case glo_color_sky_80 = "glo.color.sky.80"
|
|
case glo_color_sky_90 = "glo.color.sky.90"
|
|
case glo_color_blue_0 = "glo.color.blue.0"
|
|
case glo_color_blue_10 = "glo.color.blue.10"
|
|
case glo_color_blue_20 = "glo.color.blue.20"
|
|
case glo_color_blue_30 = "glo.color.blue.30"
|
|
case glo_color_blue_40 = "glo.color.blue.40"
|
|
case glo_color_blue_50 = "glo.color.blue.50"
|
|
case glo_color_blue_60 = "glo.color.blue.60"
|
|
case glo_color_blue_70 = "glo.color.blue.70"
|
|
case glo_color_blue_80 = "glo.color.blue.80"
|
|
case glo_color_blue_90 = "glo.color.blue.90"
|
|
case glo_color_violet_0 = "glo.color.violet.0"
|
|
case glo_color_violet_10 = "glo.color.violet.10"
|
|
case glo_color_violet_20 = "glo.color.violet.20"
|
|
case glo_color_violet_30 = "glo.color.violet.30"
|
|
case glo_color_violet_40 = "glo.color.violet.40"
|
|
case glo_color_violet_50 = "glo.color.violet.50"
|
|
case glo_color_violet_60 = "glo.color.violet.60"
|
|
case glo_color_violet_70 = "glo.color.violet.70"
|
|
case glo_color_violet_80 = "glo.color.violet.80"
|
|
case glo_color_violet_90 = "glo.color.violet.90"
|
|
case glo_color_purple_0 = "glo.color.purple.0"
|
|
case glo_color_purple_10 = "glo.color.purple.10"
|
|
case glo_color_purple_20 = "glo.color.purple.20"
|
|
case glo_color_purple_30 = "glo.color.purple.30"
|
|
case glo_color_purple_40 = "glo.color.purple.40"
|
|
case glo_color_purple_50 = "glo.color.purple.50"
|
|
case glo_color_purple_60 = "glo.color.purple.60"
|
|
case glo_color_purple_70 = "glo.color.purple.70"
|
|
case glo_color_purple_80 = "glo.color.purple.80"
|
|
case glo_color_purple_90 = "glo.color.purple.90"
|
|
case glo_color_magenta_0 = "glo.color.magenta.0"
|
|
case glo_color_magenta_10 = "glo.color.magenta.10"
|
|
case glo_color_magenta_20 = "glo.color.magenta.20"
|
|
case glo_color_magenta_30 = "glo.color.magenta.30"
|
|
case glo_color_magenta_40 = "glo.color.magenta.40"
|
|
case glo_color_magenta_50 = "glo.color.magenta.50"
|
|
case glo_color_magenta_60 = "glo.color.magenta.60"
|
|
case glo_color_magenta_70 = "glo.color.magenta.70"
|
|
case glo_color_magenta_80 = "glo.color.magenta.80"
|
|
case glo_color_magenta_90 = "glo.color.magenta.90"
|
|
case glo_color_red_0 = "glo.color.red.0"
|
|
case glo_color_red_10 = "glo.color.red.10"
|
|
case glo_color_red_20 = "glo.color.red.20"
|
|
case glo_color_red_30 = "glo.color.red.30"
|
|
case glo_color_red_40 = "glo.color.red.40"
|
|
case glo_color_red_50 = "glo.color.red.50"
|
|
case glo_color_red_60 = "glo.color.red.60"
|
|
case glo_color_red_70 = "glo.color.red.70"
|
|
case glo_color_red_80 = "glo.color.red.80"
|
|
case glo_color_red_90 = "glo.color.red.90"
|
|
case glo_color_grey_0 = "glo.color.grey.0"
|
|
case glo_color_grey_10 = "glo.color.grey.10"
|
|
case glo_color_grey_20 = "glo.color.grey.20"
|
|
case glo_color_grey_30 = "glo.color.grey.30"
|
|
case glo_color_grey_40 = "glo.color.grey.40"
|
|
case glo_color_grey_50 = "glo.color.grey.50"
|
|
case glo_color_grey_60 = "glo.color.grey.60"
|
|
case glo_color_grey_70 = "glo.color.grey.70"
|
|
case glo_color_grey_80 = "glo.color.grey.80"
|
|
case glo_color_grey_90 = "glo.color.grey.90"
|
|
case glo_color_grey_100 = "glo.color.grey.100"
|
|
case glo_color_white = "glo.color.white"
|
|
case glo_color_black = "glo.color.black"
|
|
case glo_transparent_t0 = "glo.transparent.t0"
|
|
case glo_transparent_t2 = "glo.transparent.t2"
|
|
case glo_transparent_t4 = "glo.transparent.t4"
|
|
case glo_transparent_t6 = "glo.transparent.t6"
|
|
case glo_transparent_t8 = "glo.transparent.t8"
|
|
case glo_transparent_t12 = "glo.transparent.t12"
|
|
case glo_transparent_t15 = "glo.transparent.t15"
|
|
case glo_transparent_t20 = "glo.transparent.t20"
|
|
case glo_transparent_t25 = "glo.transparent.t25"
|
|
case glo_transparent_t30 = "glo.transparent.t30"
|
|
case glo_transparent_t45 = "glo.transparent.t45"
|
|
case glo_transparent_t60 = "glo.transparent.t60"
|
|
case glo_transparent_t65 = "glo.transparent.t65"
|
|
case glo_transparent_t85 = "glo.transparent.t85"
|
|
case glo_transparent_t100 = "glo.transparent.t100"
|
|
case glo_deg_ltr = "glo.deg.ltr"
|
|
case glo_deg_ttb = "glo.deg.ttb"
|
|
case glo_deg_lttrb = "glo.deg.lttrb"
|
|
case glo_font_family_sys = "glo.font.family.sys"
|
|
case glo_font_family_sys_italic = "glo.font.family.sys.italic"
|
|
case glo_font_family_numDisplay = "glo.font.family.numDisplay"
|
|
case glo_font_family_num = "glo.font.family.num"
|
|
case glo_font_family_display = "glo.font.family.display"
|
|
case glo_font_size_64 = "glo.font.size.64"
|
|
case glo_font_size_48 = "glo.font.size.48"
|
|
case glo_font_size_36 = "glo.font.size.36"
|
|
case glo_font_size_24 = "glo.font.size.24"
|
|
case glo_font_size_20 = "glo.font.size.20"
|
|
case glo_font_size_18 = "glo.font.size.18"
|
|
case glo_font_size_16 = "glo.font.size.16"
|
|
case glo_font_size_14 = "glo.font.size.14"
|
|
case glo_font_size_12 = "glo.font.size.12"
|
|
case glo_font_weight_regular = "glo.font.weight.regular"
|
|
case glo_font_weight_medium = "glo.font.weight.medium"
|
|
case glo_font_weight_semibold = "glo.font.weight.semibold"
|
|
case glo_font_weight_bold = "glo.font.weight.bold"
|
|
case glo_font_lineheight_size64 = "glo.font.lineheight.size64"
|
|
case glo_font_lineheight_size48 = "glo.font.lineheight.size48"
|
|
case glo_font_lineheight_size36 = "glo.font.lineheight.size36"
|
|
case glo_font_lineheight_size24 = "glo.font.lineheight.size24"
|
|
case glo_font_lineheight_size20 = "glo.font.lineheight.size20"
|
|
case glo_font_lineheight_size18 = "glo.font.lineheight.size18"
|
|
case glo_font_lineheight_size16 = "glo.font.lineheight.size16"
|
|
case glo_font_lineheight_size14 = "glo.font.lineheight.size14"
|
|
case glo_font_lineheight_size12 = "glo.font.lineheight.size12"
|
|
case glo_font_lineheight_size0 = "glo.font.lineheight.size0"
|
|
case glo_radio_1_1 = "glo.radio.1.1"
|
|
case glo_radio_4_3 = "glo.radio.4.3"
|
|
case glo_radio_3_2 = "glo.radio.3.2"
|
|
case glo_radio_2_1 = "glo.radio.2.1"
|
|
case glo_radio_16_9 = "glo.radio.16.9"
|
|
case glo_radius_4 = "glo.radius.4"
|
|
case glo_radius_8 = "glo.radius.8"
|
|
case glo_radius_12 = "glo.radius.12"
|
|
case glo_radius_16 = "glo.radius.16"
|
|
case glo_radius_round = "glo.radius.round"
|
|
case glo_border_half = "glo.border.half"
|
|
case glo_border_1 = "glo.border.1"
|
|
case glo_border_2 = "glo.border.2"
|
|
case glo_border_4 = "glo.border.4"
|
|
case glo_spacing_4 = "glo.spacing.4"
|
|
case glo_spacing_8 = "glo.spacing.8"
|
|
case glo_spacing_12 = "glo.spacing.12"
|
|
case glo_spacing_16 = "glo.spacing.16"
|
|
case glo_spacing_24 = "glo.spacing.24"
|
|
case glo_spacing_32 = "glo.spacing.32"
|
|
case glo_spacing_48 = "glo.spacing.48"
|
|
case glo_spacing_64 = "glo.spacing.64"
|
|
case glo_spacing_80 = "glo.spacing.80"
|
|
case glo_spacing_128 = "glo.spacing.128"
|
|
}
|
|
|
|
func KeyForGlobalTokenFrom(_ token: CLEnumGlobalToken) -> String {
|
|
return token.rawValue
|
|
}
|
|
class CLGlobalToken {
|
|
static let baseTokens = CLBaseTokens.shared
|
|
|
|
// MARK: - Color Methods
|
|
|
|
static func color(token: CLEnumGlobalToken) -> UIColor? {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
let values = baseTokens.getTokensByKey(key)
|
|
return EPBaseObject.subGetColorByTokenValues(values)
|
|
}
|
|
|
|
static func darkColor(token: CLEnumGlobalToken) -> UIColor? {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
let values = baseTokens.getDarkTokens(key)
|
|
return EPBaseObject.subGetColorByTokenValues(values)
|
|
}
|
|
|
|
// MARK: - String Method
|
|
|
|
static func string(token: CLEnumGlobalToken) -> String? {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
return baseTokens.getTokenByKey(key)
|
|
}
|
|
|
|
// MARK: - Float Method
|
|
|
|
static func float(token: CLEnumGlobalToken) -> CGFloat {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
let value = baseTokens.getTokenByKey(key)
|
|
guard let floatValue = Float(value) else {
|
|
print("❌ Invalid float format for key: \(key)")
|
|
return 0
|
|
}
|
|
return CGFloat(floatValue)
|
|
}
|
|
|
|
// MARK: - Radius Method
|
|
|
|
static func radius(token: CLEnumGlobalToken) -> CGFloat {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
let value = baseTokens.getTokenByKey(key)
|
|
guard let radius = Float(value) else {
|
|
print("❌ Invalid radius format for key: \(key)")
|
|
return 0
|
|
}
|
|
// print("🎨 radius: \(key) \(radius)") // DLog 替换为 print
|
|
return CGFloat(radius)
|
|
}
|
|
|
|
// MARK: - Border Method
|
|
|
|
static func border(token: CLEnumGlobalToken) -> CGFloat {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
let value = baseTokens.getTokenByKey(key)
|
|
guard let border = Float(value) else {
|
|
print("❌ Invalid border format for key: \(key)")
|
|
return 0
|
|
}
|
|
// print("🎨 border: \(key) \(border)") // DLog 替换为 print
|
|
return CGFloat(border)
|
|
}
|
|
|
|
// MARK: - Shadow Method
|
|
|
|
static func shadow(token: CLEnumGlobalToken) -> EPShadow {
|
|
let key = KeyForGlobalTokenFrom(token)
|
|
let values = baseTokens.getTokensByKey(key)
|
|
|
|
guard values.count == 4, values.first?.contains(EPConfigShadowPrefix) == true else {
|
|
assertionFailure("Wrong format for shadow token: \(key)")
|
|
return EPShadow()
|
|
}
|
|
|
|
var shadow = EPShadow()
|
|
|
|
if let colorStr = values.first?.replacingOccurrences(of: EPConfigShadowPrefix, with: "") {
|
|
let color = EPBaseObject.subGetColorByTokenValues([colorStr])
|
|
shadow.color = color
|
|
}
|
|
|
|
if let opacity = Float(values[1]) {
|
|
shadow.opacity = opacity
|
|
}
|
|
let offXy = values[2].components(separatedBy: "&")
|
|
if offXy.count == 2,
|
|
let x = Float(offXy[0]), let y = Float(offXy[1]) {
|
|
shadow.offset = CGSize(width: CGFloat(x), height: CGFloat(y))
|
|
}
|
|
|
|
if let radius = Float(values[3]) {
|
|
shadow.radius = CGFloat(radius)
|
|
}
|
|
|
|
return shadow
|
|
}
|
|
|
|
}
|