feat: improve epub reader controls and annotations
This commit is contained in:
@@ -110,6 +110,10 @@ public struct RDEPUBHighlight: Codable, Equatable {
|
||||
|
||||
public var note: String?
|
||||
|
||||
/// True when this record was created directly as an annotation instead of
|
||||
/// adding a note to an existing underline.
|
||||
public var isAnnotationOnly: Bool
|
||||
|
||||
public var createdAt: Date
|
||||
|
||||
public init(
|
||||
@@ -118,9 +122,10 @@ public struct RDEPUBHighlight: Codable, Equatable {
|
||||
location: RDEPUBLocation,
|
||||
text: String,
|
||||
rangeInfo: String? = nil,
|
||||
style: RDEPUBHighlightStyle = .highlight,
|
||||
style: RDEPUBHighlightStyle = .underline,
|
||||
color: String = "#F8E16C",
|
||||
note: String? = nil,
|
||||
isAnnotationOnly: Bool = false,
|
||||
createdAt: Date = Date()
|
||||
) {
|
||||
self.id = id
|
||||
@@ -131,6 +136,7 @@ public struct RDEPUBHighlight: Codable, Equatable {
|
||||
self.style = style
|
||||
self.color = color
|
||||
self.note = note?.nilIfEmpty
|
||||
self.isAnnotationOnly = isAnnotationOnly
|
||||
self.createdAt = createdAt
|
||||
}
|
||||
|
||||
@@ -152,6 +158,7 @@ public struct RDEPUBHighlight: Codable, Equatable {
|
||||
case style
|
||||
case color
|
||||
case note
|
||||
case isAnnotationOnly
|
||||
case createdAt
|
||||
}
|
||||
|
||||
@@ -164,12 +171,13 @@ public struct RDEPUBHighlight: Codable, Equatable {
|
||||
rangeInfo = try container.decodeIfPresent(String.self, forKey: .rangeInfo)?.nilIfEmpty
|
||||
if let rawStyle = try container.decodeIfPresent(String.self, forKey: .style),
|
||||
let decodedStyle = RDEPUBHighlightStyle(rawValue: rawStyle) {
|
||||
style = decodedStyle
|
||||
style = decodedStyle == .highlight ? .underline : decodedStyle
|
||||
} else {
|
||||
style = .highlight
|
||||
style = .underline
|
||||
}
|
||||
color = try container.decodeIfPresent(String.self, forKey: .color) ?? "#F8E16C"
|
||||
note = try container.decodeIfPresent(String.self, forKey: .note)?.nilIfEmpty
|
||||
isAnnotationOnly = try container.decodeIfPresent(Bool.self, forKey: .isAnnotationOnly) ?? false
|
||||
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) ?? Date()
|
||||
}
|
||||
|
||||
@@ -183,6 +191,7 @@ public struct RDEPUBHighlight: Codable, Equatable {
|
||||
try container.encode(style, forKey: .style)
|
||||
try container.encode(color, forKey: .color)
|
||||
try container.encodeIfPresent(note, forKey: .note)
|
||||
try container.encode(isAnnotationOnly, forKey: .isAnnotationOnly)
|
||||
try container.encode(createdAt, forKey: .createdAt)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user