feat: EPUB阅读器搜索、注释、CFI模块及大书远距跳转优化
- 实现EPUB阅读器搜索功能及选中注释功能 - 优化CFI模块,修复代码审查发现的11个问题 - 实现大书远距目录跳转与后台补全优化方案 - 优化设置面板与章节运行时联动 - 重构及大量改进优化
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
// RDEPUBSearchModels.swift
|
||||
// EPUB 搜索相关数据模型
|
||||
// 定义搜索匹配项(RDEPUBSearchMatch)、搜索结果(RDEPUBSearchResult)、
|
||||
// 搜索状态(RDEPUBSearchState)和搜索展示(RDEPUBSearchPresentation)等数据结构。
|
||||
|
||||
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 var cfi: String?
|
||||
|
||||
public var rangeCFI: String?
|
||||
|
||||
public init(
|
||||
href: String,
|
||||
progression: Double,
|
||||
@@ -29,7 +28,9 @@ public struct RDEPUBSearchMatch: Codable, Equatable {
|
||||
localMatchIndex: Int,
|
||||
rangeLocation: Int? = nil,
|
||||
rangeLength: Int,
|
||||
rangeAnchor: RDEPUBTextRangeAnchor? = nil
|
||||
rangeAnchor: RDEPUBTextRangeAnchor? = nil,
|
||||
cfi: String? = nil,
|
||||
rangeCFI: String? = nil
|
||||
) {
|
||||
self.href = href
|
||||
self.progression = progression
|
||||
@@ -38,18 +39,19 @@ public struct RDEPUBSearchMatch: Codable, Equatable {
|
||||
self.rangeLocation = rangeLocation
|
||||
self.rangeLength = rangeLength
|
||||
self.rangeAnchor = rangeAnchor
|
||||
self.cfi = cfi
|
||||
self.rangeCFI = rangeCFI
|
||||
}
|
||||
}
|
||||
|
||||
/// 搜索结果摘要,包含关键词、总匹配数和当前匹配项
|
||||
public struct RDEPUBSearchResult: Codable, Equatable {
|
||||
/// 搜索关键词
|
||||
|
||||
public var keyword: String
|
||||
/// 总匹配数量
|
||||
|
||||
public var totalMatchCount: Int
|
||||
/// 当前匹配项的索引(从 1 开始)
|
||||
|
||||
public var currentMatchIndex: Int?
|
||||
/// 当前高亮的匹配项
|
||||
|
||||
public var currentMatch: RDEPUBSearchMatch?
|
||||
|
||||
public init(
|
||||
@@ -65,13 +67,12 @@ public struct RDEPUBSearchResult: Codable, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 搜索状态,管理关键词、匹配列表和当前索引
|
||||
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) {
|
||||
@@ -80,7 +81,6 @@ public struct RDEPUBSearchState: Codable, Equatable {
|
||||
self.currentMatchIndex = currentMatchIndex
|
||||
}
|
||||
|
||||
/// 获取当前匹配项
|
||||
public var currentMatch: RDEPUBSearchMatch? {
|
||||
guard let currentMatchIndex,
|
||||
matches.indices.contains(currentMatchIndex) else {
|
||||
@@ -89,7 +89,6 @@ public struct RDEPUBSearchState: Codable, Equatable {
|
||||
return matches[currentMatchIndex]
|
||||
}
|
||||
|
||||
/// 转换为搜索结果摘要
|
||||
public var result: RDEPUBSearchResult {
|
||||
RDEPUBSearchResult(
|
||||
keyword: keyword,
|
||||
@@ -100,13 +99,12 @@ public struct RDEPUBSearchState: Codable, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 搜索展示的单个资源信息
|
||||
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) {
|
||||
@@ -116,11 +114,10 @@ public struct RDEPUBSearchPresentationResource: Codable, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 搜索展示信息,传递给 JS 桥接脚本用于渲染搜索高亮
|
||||
public struct RDEPUBSearchPresentation: Codable, Equatable {
|
||||
/// 搜索关键词
|
||||
|
||||
public var keyword: String
|
||||
/// 各资源的搜索展示信息列表
|
||||
|
||||
public var resources: [RDEPUBSearchPresentationResource]
|
||||
|
||||
public init(keyword: String, resources: [RDEPUBSearchPresentationResource]) {
|
||||
|
||||
Reference in New Issue
Block a user