refactor: 添加中文注释 + 优化模块结构
- 给全部 78 个 Swift 源文件添加详细的中文注释(文件级、类级、方法级) - 删除 LegacyRDReaderController/ 死代码目录(16 文件 4592 行) - 根目录翻页容器文件移入 ReaderView/ 目录 - Resources/ 移入 EPUBCore/Resources/(与使用者归属一致) - RDEPUBTextIndexTable.swift 移入 EPUBTextRendering/(消除反向依赖) - RDURLReaderController.swift 移入 EPUBUI/(入口控制器归入 UI 层) - 更新 podspec 资源路径
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
// RDEPUBStyleSheetBuilder.swift
|
||||
// EPUB CSS 样式构建器
|
||||
// 负责生成重排模式下的分页 CSS(多列布局)和测量 CSS,
|
||||
// 以及将分页样式注入到 HTML 中。还提供测量脚本(JS)用于计算页数。
|
||||
|
||||
import Foundation
|
||||
|
||||
/// CSS 样式构建工具集,生成分页、渲染和测量所需的 CSS/JS
|
||||
public enum RDEPUBStyleSheetBuilder {
|
||||
/// 将分页 CSS 注入到 HTML 字符串中(插入 </head> 或 <body 之前)
|
||||
public static func injectPaginationCSS(
|
||||
into html: String,
|
||||
presentation: RDEPUBPresentationStyle
|
||||
@@ -15,6 +22,8 @@ public enum RDEPUBStyleSheetBuilder {
|
||||
return styleTag + html
|
||||
}
|
||||
|
||||
/// 生成重排模式的渲染 CSS(视口、body、#ss-reader-viewport、#ss-reader-content 等)
|
||||
/// 包含多列布局、字号、行高、主题色、高亮样式等
|
||||
public static func renderCSS(for presentation: RDEPUBPresentationStyle) -> String {
|
||||
let values = cssValues(for: presentation)
|
||||
let backgroundCSS = presentation.themeBackgroundColor.map { "background: \($0) !important;" } ?? ""
|
||||
@@ -95,6 +104,7 @@ public enum RDEPUBStyleSheetBuilder {
|
||||
"""
|
||||
}
|
||||
|
||||
/// 生成分页测量用的 CSS(与渲染 CSS 类似但不含 transform/will-change 等优化属性)
|
||||
public static func measurementCSS(for presentation: RDEPUBPresentationStyle) -> String {
|
||||
let values = cssValues(for: presentation)
|
||||
let backgroundCSS = presentation.themeBackgroundColor.map { "background: \($0) !important;" } ?? ""
|
||||
@@ -139,6 +149,7 @@ public enum RDEPUBStyleSheetBuilder {
|
||||
"""
|
||||
}
|
||||
|
||||
/// 生成分页测量脚本(JS):注入 CSS 后测量 scrollWidth,计算页数
|
||||
public static func measurementScript(for presentation: RDEPUBPresentationStyle) -> String {
|
||||
let style = measurementCSS(for: presentation)
|
||||
.replacingOccurrences(of: "\\", with: "\\\\")
|
||||
@@ -170,6 +181,7 @@ public enum RDEPUBStyleSheetBuilder {
|
||||
"""
|
||||
}
|
||||
|
||||
/// 从展示样式计算所有 CSS 变量值(视口尺寸、内边距、字号、行高等)
|
||||
private static func cssValues(for presentation: RDEPUBPresentationStyle) -> (
|
||||
viewportWidth: String,
|
||||
viewportHeight: String,
|
||||
|
||||
Reference in New Issue
Block a user