Repository Public License
1import SwiftUI23/// The type scale. Every role maps to a system text style, so the whole scale follows Dynamic Type; the typeface is4/// SF Pro (the system font), with SF Mono for code.5public enum LunarTextStyle: String, Sendable, CaseIterable {6 case display, title, title2, headline, body, bodyEmphasized, callout, subheadline, footnote, caption, overline7 case mono89 public var font: Font {10 switch self {11 case .display: .system(.largeTitle, design: .default, weight: .semibold)12 case .title: .system(.title, design: .default, weight: .semibold)13 case .title2: .system(.title3, design: .default, weight: .semibold)14 case .headline: .system(.headline, design: .default, weight: .semibold)15 case .body: .system(.body, design: .default, weight: .regular)16 case .bodyEmphasized: .system(.body, design: .default, weight: .medium)17 case .callout: .system(.callout, design: .default, weight: .regular)18 case .subheadline: .system(.subheadline, design: .default, weight: .medium)19 case .footnote: .system(.footnote, design: .default, weight: .regular)20 case .caption: .system(.caption, design: .default, weight: .medium)21 case .overline: .system(.caption2, design: .default, weight: .semibold)22 case .mono: .system(.callout, design: .monospaced, weight: .regular)23 }24 }2526 /// Extra letter spacing; only the overline is tracked out.27 public var tracking: CGFloat { self == .overline ? 0.8 : 0 }2829 /// The underlying system text style (documentation and token export).30 public var systemStyleName: String {31 switch self {32 case .display: "largeTitle"33 case .title: "title"34 case .title2: "title3"35 case .headline: "headline"36 case .body, .bodyEmphasized: "body"37 case .callout, .mono: "callout"38 case .subheadline: "subheadline"39 case .footnote: "footnote"40 case .caption: "caption"41 case .overline: "caption2"42 }43 }44}4546extension View {47 /// Applies a role of the Lunar type scale.48 public func lunarFont(_ style: LunarTextStyle) -> some View {49 font(style.font).tracking(style.tracking)50 }5152 /// Tabular (fixed-width) digits: use for every number that updates or lines up in a column.53 public func lunarTabularDigits() -> some View {54 monospacedDigit()55 }56}57