ReadViewSDK/Sources/RDReaderView/EPUBCore/RDEPUBSearchModels.swift
shen 54798ba578 refactor: 添加中文注释 + 优化模块结构
- 给全部 78 个 Swift 源文件添加详细的中文注释(文件级、类级、方法级)
- 删除 LegacyRDReaderController/ 死代码目录(16 文件 4592 行)
- 根目录翻页容器文件移入 ReaderView/ 目录
- Resources/ 移入 EPUBCore/Resources/(与使用者归属一致)
- RDEPUBTextIndexTable.swift 移入 EPUBTextRendering/(消除反向依赖)
- RDURLReaderController.swift 移入 EPUBUI/(入口控制器归入 UI 层)
- 更新 podspec 资源路径
2026-05-25 10:19:14 +08:00

131 lines
4.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// RDEPUBSearchModels.swift
// EPUB
// RDEPUBSearchMatchRDEPUBSearchResult
// RDEPUBSearchStateRDEPUBSearchPresentation
import Foundation
///
public struct RDEPUBSearchMatch: Codable, Equatable {
/// href
public var href: String
/// 0.0 ~ 1.0
public var progression: Double
///
public var previewText: String
///
public var localMatchIndex: Int
///
public var rangeLocation: Int?
///
public var rangeLength: Int
///
public var rangeAnchor: RDEPUBTextRangeAnchor?
public init(
href: String,
progression: Double,
previewText: String,
localMatchIndex: Int,
rangeLocation: Int? = nil,
rangeLength: Int,
rangeAnchor: RDEPUBTextRangeAnchor? = nil
) {
self.href = href
self.progression = progression
self.previewText = previewText
self.localMatchIndex = localMatchIndex
self.rangeLocation = rangeLocation
self.rangeLength = rangeLength
self.rangeAnchor = rangeAnchor
}
}
///
public struct RDEPUBSearchResult: Codable, Equatable {
///
public var keyword: String
///
public var totalMatchCount: Int
/// 1
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]
/// 0
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 {
/// href
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
}
}
/// JS
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
}
}