ReadViewSDK/Sources/RDReaderView/EPUBCore/RDEPUBParser+ReadingProfile.swift
shenlei c65c190b71 feat: EPUB阅读器搜索、注释、CFI模块及大书远距跳转优化
- 实现EPUB阅读器搜索功能及选中注释功能
- 优化CFI模块,修复代码审查发现的11个问题
- 实现大书远距目录跳转与后台补全优化方案
- 优化设置面板与章节运行时联动
- 重构及大量改进优化
2026-06-22 20:26:34 +08:00

47 lines
1.7 KiB
Swift

import Foundation
extension RDEPUBParser {
public func readingProfile() -> RDEPUBReadingProfile {
if metadata.layout == .fixed {
return .webFixedLayout
}
return hasInteractiveContent() ? .webInteractive : .textReflowable
}
public func hasInteractiveContent() -> Bool {
let interactiveMediaTypes = [
"application/javascript",
"text/javascript",
"application/ecmascript"
]
if manifest.values.contains(where: { item in
interactiveMediaTypes.contains(item.mediaType.lowercased()) || item.properties.contains("scripted")
}) {
return true
}
for item in spine where item.linear && (item.mediaType.contains("html") || item.mediaType.contains("xhtml")) {
guard let html = htmlString(forRelativePath: item.href) else {
continue
}
if containsInteractiveMarkup(html) {
return true
}
}
return false
}
private func containsInteractiveMarkup(_ html: String) -> Bool {
let interactivePattern = #"<(script|iframe|video|audio|canvas|object|embed)\b|\bon(load|click|touchstart|touchend|mouseover|submit|change|input)=|hype_generated_script|swiper|webview"#
if html.range(of: interactivePattern, options: [.regularExpression, .caseInsensitive]) != nil {
return true
}
let dynamicSVGPattern = #"<svg\b[^>]*>[\s\S]*?(<(script|foreignObject|animate|animateMotion|animateTransform|set)\b|\bon(load|click|touchstart|touchend|mouseover)=)"#
return html.range(of: dynamicSVGPattern, options: [.regularExpression, .caseInsensitive]) != nil
}
}