aboutsummaryrefslogtreecommitdiff
path: root/Sources/NorgKit/Models/InlineStyle.swift
blob: 807de7bd7f7c134c7eeac7e99184a5818c3a239d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/// Composable inline styles that may be applied to a single run of text.
public struct InlineStyle: OptionSet, Hashable, Sendable, Codable {
  public let rawValue: Int

  public init(rawValue: Int) {
    self.rawValue = rawValue
  }

  public static let bold = InlineStyle(rawValue: 1 << 0)
  public static let italic = InlineStyle(rawValue: 1 << 1)
  public static let underline = InlineStyle(rawValue: 1 << 2)
  public static let strikethrough = InlineStyle(rawValue: 1 << 3)
  public static let verbatim = InlineStyle(rawValue: 1 << 4)
  public static let superscript = InlineStyle(rawValue: 1 << 5)
  public static let `subscript` = InlineStyle(rawValue: 1 << 6)
  public static let spoiler = InlineStyle(rawValue: 1 << 7)
  public static let math = InlineStyle(rawValue: 1 << 8)

  public init(from decoder: Decoder) throws {
    let container = try decoder.singleValueContainer()
    self.init(rawValue: try container.decode(Int.self))
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.singleValueContainer()
    try container.encode(rawValue)
  }
}