feat: chapter runtime refactoring and related updates

- Refactor chapter runtime: replace window coordinator/snapshot with warmup orchestrator
- Update EPUB core: parser, reading session, JS bridge, navigator layout
- Update reader controller: data source, location resolution, persistence
- Update chapter runtime: data cache, loader, runtime store, disk cache, warmup orchestrator
- Remove deprecated navigation state machine and pagination state
- Update text rendering: book cache, HTML normalizer
- Update UI: text content view, dark image adjuster, text selection controller
- Update settings and reader configuration
- Add CODE_REVIEW.md and AUDIT_FINAL.md documentation
- Update pod dependencies (remove SSAlertSwift, SnapKit)
- Update podspec and pod configuration files

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-06-26 18:50:07 +09:00
co-authored by Claude
parent b8aa10c535
commit 22e7e44220
123 changed files with 3701 additions and 9118 deletions
@@ -77,60 +77,104 @@ public final class RDEPUBUserDefaultsPersistence: RDEPUBReaderPersistence {
guard let data = defaults.data(forKey: locationPrefix + bookIdentifier) else {
return nil
}
return try? JSONDecoder().decode(RDEPUBLocation.self, from: data)
do {
return try JSONDecoder().decode(RDEPUBLocation.self, from: data)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to decode location for '\(bookIdentifier)': \(error)")
#endif
return nil
}
}
public func saveLocation(_ location: RDEPUBLocation, for bookIdentifier: String) {
guard let data = try? JSONEncoder().encode(location) else {
return
do {
let data = try JSONEncoder().encode(location)
defaults.set(data, forKey: locationPrefix + bookIdentifier)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to encode location for '\(bookIdentifier)': \(error)")
#endif
}
defaults.set(data, forKey: locationPrefix + bookIdentifier)
}
public func loadBookmarks(for bookIdentifier: String) -> [RDEPUBBookmark] {
guard let data = defaults.data(forKey: bookmarksPrefix + bookIdentifier) else {
return []
}
return (try? JSONDecoder().decode([RDEPUBBookmark].self, from: data)) ?? []
do {
return try JSONDecoder().decode([RDEPUBBookmark].self, from: data)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to decode bookmarks for '\(bookIdentifier)': \(error)")
#endif
return []
}
}
public func saveBookmarks(_ bookmarks: [RDEPUBBookmark], for bookIdentifier: String) {
guard let data = try? JSONEncoder().encode(bookmarks) else {
return
do {
let data = try JSONEncoder().encode(bookmarks)
defaults.set(data, forKey: bookmarksPrefix + bookIdentifier)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to encode bookmarks for '\(bookIdentifier)': \(error)")
#endif
}
defaults.set(data, forKey: bookmarksPrefix + bookIdentifier)
}
public func loadHighlights(for bookIdentifier: String) -> [RDEPUBHighlight] {
guard let data = defaults.data(forKey: highlightsPrefix + bookIdentifier) else {
return []
}
return (try? JSONDecoder().decode([RDEPUBHighlight].self, from: data)) ?? []
do {
return try JSONDecoder().decode([RDEPUBHighlight].self, from: data)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to decode highlights for '\(bookIdentifier)': \(error)")
#endif
return []
}
}
public func saveHighlights(_ highlights: [RDEPUBHighlight], for bookIdentifier: String) {
guard let data = try? JSONEncoder().encode(highlights) else {
return
}
if data.count > 1_048_576 {
do {
let data = try JSONEncoder().encode(highlights)
if data.count > 1_048_576 {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ saveHighlights data size (\(data.count) bytes) exceeds 1MB for: \(bookIdentifier)")
#endif
}
defaults.set(data, forKey: highlightsPrefix + bookIdentifier)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ saveHighlights data size (\(data.count) bytes) exceeds 1MB for: \(bookIdentifier)")
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to encode highlights for '\(bookIdentifier)': \(error)")
#endif
}
defaults.set(data, forKey: highlightsPrefix + bookIdentifier)
}
public func loadReaderSettings() -> RDEPUBReaderSettings? {
guard let data = defaults.data(forKey: settingsKey) else {
return nil
}
return try? JSONDecoder().decode(RDEPUBReaderSettings.self, from: data)
do {
return try JSONDecoder().decode(RDEPUBReaderSettings.self, from: data)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to decode reader settings: \(error)")
#endif
return nil
}
}
public func saveReaderSettings(_ settings: RDEPUBReaderSettings) {
guard let data = try? JSONEncoder().encode(settings) else {
return
do {
let data = try JSONEncoder().encode(settings)
defaults.set(data, forKey: settingsKey)
} catch {
#if DEBUG
print("[RDEPUBUserDefaultsPersistence] ⚠️ Failed to encode reader settings: \(error)")
#endif
}
defaults.set(data, forKey: settingsKey)
}
}