Epub阅读器0.0.1
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import Foundation
|
||||
|
||||
public struct RDEPUBSearchMatch: Codable, Equatable {
|
||||
public var href: String
|
||||
public var progression: Double
|
||||
public var previewText: String
|
||||
public var localMatchIndex: Int
|
||||
public var rangeLocation: Int?
|
||||
public var rangeLength: Int
|
||||
|
||||
public init(
|
||||
href: String,
|
||||
progression: Double,
|
||||
previewText: String,
|
||||
localMatchIndex: Int,
|
||||
rangeLocation: Int? = nil,
|
||||
rangeLength: Int
|
||||
) {
|
||||
self.href = href
|
||||
self.progression = progression
|
||||
self.previewText = previewText
|
||||
self.localMatchIndex = localMatchIndex
|
||||
self.rangeLocation = rangeLocation
|
||||
self.rangeLength = rangeLength
|
||||
}
|
||||
}
|
||||
|
||||
public struct RDEPUBSearchResult: Codable, Equatable {
|
||||
public var keyword: String
|
||||
public var totalMatchCount: Int
|
||||
public var currentMatchIndex: Int?
|
||||
public var currentMatch: RDEPUBSearchMatch?
|
||||
|
||||
public init(
|
||||
keyword: String,
|
||||
totalMatchCount: Int,
|
||||
currentMatchIndex: Int?,
|
||||
currentMatch: RDEPUBSearchMatch?
|
||||
) {
|
||||
self.keyword = keyword
|
||||
self.totalMatchCount = totalMatchCount
|
||||
self.currentMatchIndex = currentMatchIndex
|
||||
self.currentMatch = currentMatch
|
||||
}
|
||||
}
|
||||
|
||||
public struct RDEPUBSearchState: Codable, Equatable {
|
||||
public var keyword: String
|
||||
public var matches: [RDEPUBSearchMatch]
|
||||
public var currentMatchIndex: Int?
|
||||
|
||||
public init(keyword: String, matches: [RDEPUBSearchMatch], currentMatchIndex: Int? = nil) {
|
||||
self.keyword = keyword
|
||||
self.matches = matches
|
||||
self.currentMatchIndex = currentMatchIndex
|
||||
}
|
||||
|
||||
public var currentMatch: RDEPUBSearchMatch? {
|
||||
guard let currentMatchIndex,
|
||||
matches.indices.contains(currentMatchIndex) else {
|
||||
return nil
|
||||
}
|
||||
return matches[currentMatchIndex]
|
||||
}
|
||||
|
||||
public var result: RDEPUBSearchResult {
|
||||
RDEPUBSearchResult(
|
||||
keyword: keyword,
|
||||
totalMatchCount: matches.count,
|
||||
currentMatchIndex: currentMatchIndex.map { $0 + 1 },
|
||||
currentMatch: currentMatch
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public struct RDEPUBSearchPresentationResource: Codable, Equatable {
|
||||
public var href: String
|
||||
public var matchCount: Int
|
||||
public var activeLocalMatchIndex: Int?
|
||||
|
||||
public init(href: String, matchCount: Int, activeLocalMatchIndex: Int? = nil) {
|
||||
self.href = href
|
||||
self.matchCount = matchCount
|
||||
self.activeLocalMatchIndex = activeLocalMatchIndex
|
||||
}
|
||||
}
|
||||
|
||||
public struct RDEPUBSearchPresentation: Codable, Equatable {
|
||||
public var keyword: String
|
||||
public var resources: [RDEPUBSearchPresentationResource]
|
||||
|
||||
public init(keyword: String, resources: [RDEPUBSearchPresentationResource]) {
|
||||
self.keyword = keyword
|
||||
self.resources = resources
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user