- 新增 RDEPUBTextStatisticsCoordinator:后台单线程按章渲染统计全书字符数,footer 显示精确阅读百分比;统计未就绪时(含 PageMap 未覆盖的 loading 页)显示"计算中",不再回退旧页码 - 统计结果按 bookID + renderSignature + 章节内容哈希做磁盘缓存,布局/字号变化自动失效;缓存命中不创建 renderer - 移除"0.8 秒翻页时间窗轮询让路"逻辑,后续由事件驱动的交互加载门替代(见方案文档 5.6 节) - 新增 Doc/FeatureSolution/TEXT_STATISTICS_PIPELINE_OPTIMIZATION.md:三条渲染流水线收敛为"交互 + 生产者"、交互加载门、全局后台渲染预算池、后台渲染登记表、两阶段近似百分比、自适应并发的完整优化方案与验收标准 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
82 lines
2.1 KiB
Swift
82 lines
2.1 KiB
Swift
import UIKit
|
|
|
|
/// M-01: All properties must be accessed exclusively from the main thread.
|
|
/// This is currently enforced by convention — all verified access paths are main-thread-only.
|
|
/// Adding @MainActor would formalize this but requires iOS 15+ and Swift concurrency throughout.
|
|
/// For now, rely on the audit-verified access patterns and consider @MainActor in a future refactor.
|
|
final class RDEPUBReaderState {
|
|
|
|
var parser: RDEPUBParser?
|
|
|
|
var publication: RDEPUBPublication?
|
|
|
|
var readingSession: RDEPUBReadingSession?
|
|
|
|
var textBook: RDEPUBTextBook?
|
|
|
|
var bookPageMap: RDEPUBBookPageMap?
|
|
|
|
var textStatistics: RDEPUBBookTextStatistics?
|
|
|
|
var activeBookmarks: [RDEPUBBookmark] = []
|
|
|
|
var activeHighlights: [RDEPUBHighlight] = []
|
|
|
|
var currentBookIdentifier: String?
|
|
|
|
var paginationToken = UUID()
|
|
|
|
var textStatisticsToken = UUID()
|
|
|
|
var searchState: RDEPUBSearchState?
|
|
|
|
var pendingPageMapUpdates: [RDEPUBPendingPageMapUpdate] = []
|
|
|
|
var lastTextPaginationPageSize: CGSize?
|
|
|
|
var lastMetadataParseWallClockMs: Int = 0
|
|
|
|
var lastMetadataParseConcurrency: Int = 0
|
|
|
|
var lastTextStatisticsWallClockMs: Int = 0
|
|
|
|
var selectionState: RDEPUBSelectionState = .idle
|
|
|
|
var isRepaginating: Bool = false
|
|
|
|
var didStartInitialLoad: Bool = false
|
|
|
|
var isExternalTextBook: Bool = false
|
|
|
|
var textFileURL: URL?
|
|
|
|
let textBookCache = RDEPUBTextBookCache()
|
|
|
|
var currentSelection: RDEPUBSelection? {
|
|
get { selectionState.selection }
|
|
set {
|
|
if let newValue, !newValue.isEmpty {
|
|
selectionState = .selected(newValue)
|
|
} else {
|
|
selectionState = .idle
|
|
}
|
|
}
|
|
}
|
|
|
|
var activePages: [EPUBPage] {
|
|
readingSession?.activePages ?? []
|
|
}
|
|
|
|
var activeChapters: [EPUBChapterInfo] {
|
|
readingSession?.activeChapters ?? []
|
|
}
|
|
|
|
func replaceActiveSnapshot(_ snapshot: RDEPUBReadingSession.PaginationSnapshot) {
|
|
readingSession?.setActiveSnapshot(snapshot)
|
|
}
|
|
|
|
func clearActiveSnapshot() {
|
|
readingSession?.resetRuntimeState()
|
|
}
|
|
}
|