refactored out mapped and inserted within the only function that calls it.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-02-28 15:32:00 -06:00
parent 54c431534b
commit 995bec6cb2

View File

@ -12,7 +12,25 @@ import VDS
extension Styler.Font {
//Converts Legacy Font to a VDS.TextStyle
public func vdsTextStyle() -> VDS.TextStyle? {
let updatedRaw = mapped().rawValue.replacingOccurrences(of: "Regular", with: "")
//ensure that the current Styler.Font isn't Legacy Version
//if it is, here is the conversion to the updated version
var actualFont: Styler.Font = self
switch self {
case .Title2XLarge: actualFont = .RegularTitle2XLarge
case .TitleXLarge: actualFont = .RegularTitleXLarge
case .H1: actualFont = .RegularTitle2XLarge
case .H32: actualFont = .RegularTitleXLarge
case .H2: actualFont = .RegularTitleLarge
case .B20: actualFont = .RegularBodyLarge
case .H3: actualFont = .BoldTitleMedium
case .B1: actualFont = .BoldBodySmall
case .B2: actualFont = .RegularBodySmall
case .B3: actualFont = .RegularMicro
default: break
}
let updatedRaw = actualFont.rawValue.replacingOccurrences(of: "Regular", with: "")
let newRaw = updatedRaw.prefix(1).lowercased() + updatedRaw.dropFirst()
guard let style = VDS.TextStyle(rawValue: newRaw) else { return nil }
return style
@ -29,24 +47,6 @@ extension Styler.Font {
}
return standardStyle
}
private func mapped() -> Styler.Font {
var mapped: Styler.Font = self
switch self {
case .Title2XLarge: mapped = .RegularTitle2XLarge
case .TitleXLarge: mapped = .RegularTitleXLarge
case .H1: mapped = .RegularTitle2XLarge
case .H32: mapped = .RegularTitleXLarge
case .H2: mapped = .RegularTitleLarge
case .B20: mapped = .RegularBodyLarge
case .H3: mapped = .BoldTitleMedium
case .B1: mapped = .BoldBodySmall
case .B2: mapped = .RegularBodySmall
case .B3: mapped = .RegularMicro
default: break
}
return mapped
}
}
extension VDS.Font {