refactor: 添加中文注释 + 优化模块结构

- 给全部 78 个 Swift 源文件添加详细的中文注释(文件级、类级、方法级)
- 删除 LegacyRDReaderController/ 死代码目录(16 文件 4592 行)
- 根目录翻页容器文件移入 ReaderView/ 目录
- Resources/ 移入 EPUBCore/Resources/(与使用者归属一致)
- RDEPUBTextIndexTable.swift 移入 EPUBTextRendering/(消除反向依赖)
- RDURLReaderController.swift 移入 EPUBUI/(入口控制器归入 UI 层)
- 更新 podspec 资源路径
This commit is contained in:
shen
2026-05-25 10:19:14 +08:00
parent 5af90c1148
commit 54798ba578
88 changed files with 2492 additions and 4469 deletions
@@ -1,11 +1,18 @@
// RDEPUBParser+Resources.swift
// EPUB URL
// IDhref manifest spine href
// ss-reader:// URL HTML
import Foundation
import UIKit
extension RDEPUBParser {
/// ID manifest
public func manifestItem(for id: String) -> RDEPUBManifestItem? {
manifest[id]
}
/// href manifest fragment
public func manifestItem(forHref href: String) -> RDEPUBManifestItem? {
let target = href.components(separatedBy: "#").first ?? href
return manifest.values.first { item in
@@ -13,11 +20,13 @@ extension RDEPUBParser {
}
}
/// spine href
public func href(forSpineIndex index: Int) -> String? {
guard spine.indices.contains(index) else { return nil }
return spine[index].href
}
/// URL
public func fileURL(forRelativePath relativePath: String) -> URL? {
guard let opfDirectoryURL else { return nil }
let path = relativePath.components(separatedBy: "#").first ?? relativePath
@@ -32,6 +41,7 @@ extension RDEPUBParser {
return resolvedURL
}
/// ss-reader://book/ URL WebView
public func resourceURL(forRelativePath relativePath: String) -> URL? {
let normalizedPath = relativePath.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
guard !normalizedPath.isEmpty else { return nil }
@@ -45,6 +55,7 @@ extension RDEPUBParser {
return components.url
}
/// ss-reader://book/ URL URL
public func fileURL(forResourceURL resourceURL: URL) -> URL? {
guard resourceURL.scheme == RDEPUBResourceURLSchemeHandler.scheme,
resourceURL.host == RDEPUBResourceURLSchemeHandler.host else {
@@ -54,6 +65,7 @@ extension RDEPUBParser {
return fileURL(forRelativePath: relativePath)
}
/// "cover-image" ID "cover" manifest
public func coverImage() -> UIImage? {
let coverCandidates = manifest.values.filter { item in
item.properties.contains("cover-image") || item.id.lowercased().contains("cover")
@@ -67,6 +79,7 @@ extension RDEPUBParser {
return nil
}
/// spine HTML
public func htmlString(forSpineIndex index: Int) -> String? {
guard spine.indices.contains(index) else {
return nil
@@ -74,6 +87,7 @@ extension RDEPUBParser {
return htmlString(forRelativePath: spine[index].href)
}
/// HTML
public func htmlString(forRelativePath relativePath: String) -> String? {
guard let fileURL = fileURL(forRelativePath: relativePath) else {
return nil
@@ -81,6 +95,7 @@ extension RDEPUBParser {
return try? String(contentsOf: fileURL)
}
/// href URL
func normalize(href: String, relativeTo directoryURL: URL) -> String {
guard let resolvedURL = URL(string: href, relativeTo: directoryURL)?.standardizedFileURL else {
return href