ReadViewSDK/Sources/RDReaderView/EPUBUI/ReaderController/RDEPUBNavigationStateMachine.swift
shenlei 15b15d0e11 Remove all RDEPUBBackgroundTrace.log and bare print diagnostic calls
Keep only the evaluateFullPageMapTakeover: fullReplace diagnostic log
in RDEPUBPageMapReconciliationCoordinator.swift for future debugging.

Simplified RDEPUBBackgroundTrace to just the log method (removed measure
and debug gating). Removed all [EPUB][...], [ReadViewDemo], and
[EPUB][Pagination] print statements across the project.

Also includes earlier bug fixes:
- Fix stale currentPageNumber in extendPartial commit
- Fix pageCurl rebindVisiblePage during transition
- Fix keepCurrentWindow not removing pending update from queue
- Fix right-aligned text (巫鸿 bug) via avoidPageBreakInside,
  tail merger, and continuation paragraph normalization
- Add text-indent reset for aligned blocks in CSS compatibility layer

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 18:25:22 +08:00

77 lines
2.4 KiB
Swift

import Foundation
enum RDEPUBNavigationState: Equatable {
case idle
case initialLoading
case restoringLocation
case preparingChapter(spineIndex: Int)
case presentingWindow
case reconcilingFullMap
case repaginating
}
final class RDEPUBNavigationStateMachine {
private let lock = NSLock()
private(set) var state: RDEPUBNavigationState = .idle
func transition(to newState: RDEPUBNavigationState) {
lock.lock()
let oldState = state
state = newState
lock.unlock()
#if DEBUG
validateTransition(from: oldState, to: newState)
#endif
}
#if DEBUG
private func validateTransition(from oldState: RDEPUBNavigationState, to newState: RDEPUBNavigationState) {
let isValid: Bool
switch (oldState, newState) {
case (.idle, .initialLoading),
(.idle, .preparingChapter),
(.idle, .restoringLocation),
(.idle, .idle):
isValid = true
case (.initialLoading, .preparingChapter),
(.initialLoading, .presentingWindow),
(.initialLoading, .idle),
(.initialLoading, .initialLoading):
isValid = true
case (.restoringLocation, .preparingChapter),
(.restoringLocation, .presentingWindow),
(.restoringLocation, .idle),
(.restoringLocation, .restoringLocation):
isValid = true
case (.preparingChapter, .presentingWindow),
(.preparingChapter, .preparingChapter),
(.preparingChapter, .idle):
isValid = true
case (.presentingWindow, .idle),
(.presentingWindow, .reconcilingFullMap),
(.presentingWindow, .preparingChapter),
(.presentingWindow, .presentingWindow),
(.presentingWindow, .repaginating):
isValid = true
case (.reconcilingFullMap, .presentingWindow),
(.reconcilingFullMap, .idle),
(.reconcilingFullMap, .reconcilingFullMap):
isValid = true
case (.repaginating, .presentingWindow),
(.repaginating, .idle),
(.repaginating, .repaginating):
isValid = true
default:
isValid = false
}
if !isValid {
#if DEBUG
assertionFailure("Unexpected navigation state transition: \(oldState)\(newState)")
#endif
}
}
#endif
}