Skip to content

Commit

Permalink
Support light/dark prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aranoledur committed Oct 18, 2023
1 parent 1803796 commit 0499198
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions Sources/FigmaExport/Loaders/ColorsLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,46 @@ final class ColorsLoader {
let lightHCSuffix = colorParams?.lightHCModeSuffix ?? "_lightHC"
let darkHCSuffix = colorParams?.darkHCModeSuffix ?? "_darkHC"

let lightColors = colors
let lightPrefix = "light/"
let darkPrefix = "dark/"

var lightColors = colors
.filter {
!$0.name.hasSuffix(darkSuffix) &&
!$0.name.hasSuffix(lightHCSuffix) &&
!$0.name.hasSuffix(darkHCSuffix)
!$0.name.hasSuffix(lightHCSuffix) &&
!$0.name.hasSuffix(darkHCSuffix) &&
!$0.name.hasPrefix(darkPrefix)
}
// remove lightPrefix
lightColors = lightColors.map {
var newColor = $0
if newColor.name.hasPrefix(lightPrefix) {
newColor.name = String(newColor.name.dropFirst(lightPrefix.count))
return newColor
}
let darkColors = filteredColors(colors, suffix: darkSuffix)
return $0
}

var darkColors = filteredColors(colors, suffix: darkSuffix)
if darkColors.isEmpty {
darkColors = filteredColors(colors, prefix: darkPrefix)
}
let lightHCColors = filteredColors(colors, suffix: lightHCSuffix)
let darkHCColors = filteredColors(colors, suffix: darkHCSuffix)
return (lightColors, darkColors, lightHCColors, darkHCColors)
}

private func filteredColors(_ colors: [Color], prefix: String) -> [Color] {
let filteredColors = colors
.filter { $0.name.hasPrefix(prefix) }
.map { color -> Color in
var newColor = color
newColor.name = String(color.name.dropFirst(prefix.count))
return newColor
}
return filteredColors
}

private func filteredColors(_ colors: [Color], suffix: String) -> [Color] {
let filteredColors = colors
.filter { $0.name.hasSuffix(suffix) }
Expand Down

0 comments on commit 0499198

Please sign in to comment.