refactor: 添加中文注释 + 优化模块结构
- 给全部 78 个 Swift 源文件添加详细的中文注释(文件级、类级、方法级) - 删除 LegacyRDReaderController/ 死代码目录(16 文件 4592 行) - 根目录翻页容器文件移入 ReaderView/ 目录 - Resources/ 移入 EPUBCore/Resources/(与使用者归属一致) - RDEPUBTextIndexTable.swift 移入 EPUBTextRendering/(消除反向依赖) - RDURLReaderController.swift 移入 EPUBUI/(入口控制器归入 UI 层) - 更新 podspec 资源路径
This commit is contained in:
@@ -1,23 +1,41 @@
|
||||
// RDEPUBParser.swift
|
||||
// EPUB 解析器入口
|
||||
// 解析链路:epubURL → ZIP 解压 → container.xml → OPF → spine/TOC
|
||||
// 是 EPUBCore Publication 层的核心,解析完成后通过 makePublication() 生成 RDEPUBPublication。
|
||||
// 具体解析逻辑分散在 +Archive、+Package、+TOC、+Resources、+ReadingProfile 扩展中。
|
||||
|
||||
import Foundation
|
||||
|
||||
/// EPUB 解析器,执行从 epub 文件到出版物数据的完整解析流程
|
||||
/// 主链路:epubURL → extractArchiveIfNeeded → container.xml → OPF → metadata/manifest/spine/TOC
|
||||
public final class RDEPUBParser {
|
||||
/// 出版物元数据(标题、作者、语言、布局模式等)
|
||||
public internal(set) var metadata = RDEPUBMetadata()
|
||||
/// 资源清单字典(key 为 manifest item ID)
|
||||
public internal(set) var manifest: [String: RDEPUBManifestItem] = [:]
|
||||
/// 阅读顺序列表(按 spine 排列的资源项)
|
||||
public internal(set) var spine: [RDEPUBSpineItem] = []
|
||||
/// 目录树(从 NCX 或 Nav Document 解析得到)
|
||||
public internal(set) var tableOfContents: [EPUBTableOfContentsItem] = []
|
||||
/// EPUB 解压后的根目录路径
|
||||
public internal(set) var extractionRootURL: URL?
|
||||
/// OPF 文件的完整路径
|
||||
public internal(set) var opfURL: URL?
|
||||
|
||||
/// OPF 文件所在目录的 URL(用于解析相对路径)
|
||||
public var opfDirectoryURL: URL? {
|
||||
opfURL?.deletingLastPathComponent()
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
/// 基于当前解析结果创建 RDEPUBPublication(门面对象)
|
||||
public func makePublication() -> RDEPUBPublication {
|
||||
RDEPUBPublication(parser: self)
|
||||
}
|
||||
|
||||
/// 完整解析 EPUB 文件:解压 → container.xml → OPF
|
||||
/// - Parameter epubURL: EPUB 文件的本地路径
|
||||
public func parse(epubURL: URL) throws {
|
||||
reset()
|
||||
|
||||
@@ -38,6 +56,8 @@ public final class RDEPUBParser {
|
||||
try parseOPF(at: packageURL)
|
||||
}
|
||||
|
||||
/// 解析 OPF 文件:metadata/manifest/spine/TOC
|
||||
/// - Parameter opfURL: OPF 文件路径
|
||||
public func parseOPF(at opfURL: URL) throws {
|
||||
resetPublicationState()
|
||||
|
||||
@@ -61,10 +81,12 @@ public final class RDEPUBParser {
|
||||
self.tableOfContents = parseTOC(from: packageDocument, opfURL: opfURL)
|
||||
}
|
||||
|
||||
/// 获取已解析的目录
|
||||
public func parseTOC() -> [EPUBTableOfContentsItem] {
|
||||
tableOfContents
|
||||
}
|
||||
|
||||
/// 解析指定的 Navigation Document 文件
|
||||
public func parseNavDocument(_ navURL: URL, baseURL: URL? = nil) -> [EPUBTableOfContentsItem] {
|
||||
parseNavDocumentItems(at: navURL, baseURL: baseURL ?? navURL.deletingLastPathComponent())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user