refactor: rename RDReaderView -> RDEpubReaderView, update pod config and docs

- Rename source module from RDReaderView to RDEpubReaderView
- Move all source files from Sources/RDReaderView/ to Sources/RDEpubReaderView/
- Update podspec: RDReaderView.podspec -> RDEpubReaderView.podspec
- Update Podfile, demo project, and CocoaPods config for new pod name
- Delete old RDReaderView pod support files from ReadViewDemo/Pods
- Add new RDEpubReaderView pod support files
- Update documentation (API ref, architecture, UML, conventions, etc.)
- Add FixedLayoutRotationTests
- Update .gitignore: exclude .DS_Store, manual unpack backups, _ssoft-output
This commit is contained in:
shenlei
2026-07-10 19:44:53 +09:00
parent d5a7755702
commit d7fcda345d
460 changed files with 38358 additions and 2300 deletions
@@ -0,0 +1,67 @@
(function() {
if (window.WeReadApi) { return; }
function bridge() {
return window.RDEpubReaderBridge || null;
}
function sharedThemeCSS(theme) {
if (!theme) { return ''; }
var backgroundColor = theme.backgroundColor || 'transparent';
var textColor = theme.textColor || 'inherit';
return [
':root {',
' color-scheme: light;',
'}',
'html, body {',
' background: ' + backgroundColor + ' !important;',
' color: ' + textColor + ' !important;',
'}',
'a {',
' -webkit-tap-highlight-color: transparent;',
'}'
].join('\n');
}
window.WeReadApi = {
applySharedTheme: function(theme) {
var css = sharedThemeCSS(theme);
if (window.RDInjectedCSS) {
window.RDInjectedCSS.setStyle('ss-reader-theme', css, {
includeFrames: !!(theme && theme.includeFrames)
});
}
return true;
},
applyPagination: function(styleText) {
return !!(bridge() && bridge().applyPagination(styleText));
},
setPageMetrics: function(pageCount, pageStride) {
return !!(bridge() && bridge().setPageMetrics(pageCount, pageStride));
},
scrollToPage: function(pageIndex) {
return !!(bridge() && bridge().scrollToPage(pageIndex));
},
scrollToLocation: function(location, fallbackPageIndex) {
return !!(bridge() && bridge().scrollToLocation(location, fallbackPageIndex));
},
setHighlights: function(items) {
return !!(bridge() && bridge().setHighlights(items));
},
clearHighlights: function() {
return !!(bridge() && bridge().clearHighlights());
},
setSearchPresentation: function(payload) {
return !!(bridge() && bridge().setSearchPresentation(payload));
},
resolveDecorations: function() {
return bridge() ? bridge().resolveDecorations() : { highlights: [], search: [] };
},
reportProgression: function(fragment) {
return !!(bridge() && bridge().reportProgression(fragment));
},
selectionPayload: function() {
return bridge() ? bridge().selectionPayload() : null;
}
};
})();
@@ -0,0 +1,45 @@
(function() {
if (window.RDInjectedCSS) { return; }
function applyStyle(doc, identifier, cssText) {
if (!doc || !doc.head) { return; }
var style = doc.getElementById(identifier);
if (!style) {
style = doc.createElement('style');
style.id = identifier;
doc.head.appendChild(style);
}
style.textContent = cssText || '';
}
function walkDocuments(rootDoc, includeFrames, visitor) {
if (!rootDoc) { return; }
visitor(rootDoc);
if (!includeFrames || !rootDoc.querySelectorAll) { return; }
Array.prototype.forEach.call(rootDoc.querySelectorAll('iframe'), function(frame) {
try {
if (!frame.contentDocument) { return; }
walkDocuments(frame.contentDocument, includeFrames, visitor);
} catch (error) {
}
});
}
window.RDInjectedCSS = {
setStyle: function(identifier, cssText, options) {
var includeFrames = !!(options && options.includeFrames);
walkDocuments(document, includeFrames, function(doc) {
applyStyle(doc, identifier, cssText);
});
},
removeStyle: function(identifier, options) {
var includeFrames = !!(options && options.includeFrames);
walkDocuments(document, includeFrames, function(doc) {
var style = doc.getElementById(identifier);
if (style && style.parentNode) {
style.parentNode.removeChild(style);
}
});
}
};
})();
@@ -0,0 +1,550 @@
(function() {
if (window.RDEpubReaderBridge) { return; }
window.addEventListener('error', function(event) {
try {
var message = event && (event.message || (event.error && event.error.message)) || 'Unknown JavaScript error';
window.webkit.messageHandlers.{{JAVASCRIPT_ERROR_MESSAGE}}.postMessage(message);
} catch (error) {
}
});
function serializeRange(range) {
if (window.rangy && typeof window.rangy.serializeRange === 'function') {
return window.rangy.serializeRange(range, range && range.startContainer && range.startContainer.ownerDocument);
}
return null;
}
function rangeFromInfo(rangeInfo) {
if (window.rangy && typeof window.rangy.deserializeRange === 'function') {
return window.rangy.deserializeRange(rangeInfo, document);
}
return null;
}
var visiblePageIndex = 0;
var configuredPageCount = 1;
var configuredPageStride = 1;
var relayoutTimer = null;
var fixedLayoutDocument = false;
function isFixedLayoutDocument() {
if (fixedLayoutDocument) { return true; }
fixedLayoutDocument = !!document.getElementById('ss-fixed-root') || !!document.querySelector('.ss-fixed-page');
return fixedLayoutDocument;
}
function ensurePaginationStructure() {
if (isFixedLayoutDocument()) {
return null;
}
var viewport = document.getElementById('ss-reader-viewport');
var content = document.getElementById('ss-reader-content');
if (viewport && content) {
return content;
}
viewport = document.createElement('div');
viewport.id = 'ss-reader-viewport';
content = document.createElement('div');
content.id = 'ss-reader-content';
while (document.body.firstChild) {
content.appendChild(document.body.firstChild);
}
viewport.appendChild(content);
document.body.appendChild(viewport);
return content;
}
function paginationContent() {
if (isFixedLayoutDocument()) {
return null;
}
return ensurePaginationStructure();
}
function effectivePageStride() {
return Math.max(1, configuredPageStride || 1);
}
function measuredPageCount() {
if (isFixedLayoutDocument()) {
return 1;
}
var content = paginationContent();
var scrollingElement = document.scrollingElement || document.documentElement || document.body;
var scrollWidth = Math.max(
content ? content.scrollWidth : 0,
content ? content.offsetWidth : 0,
scrollingElement ? scrollingElement.scrollWidth : 0,
document.documentElement ? document.documentElement.scrollWidth : 0,
document.body ? document.body.scrollWidth : 0,
effectivePageStride()
);
return Math.max(1, Math.ceil(scrollWidth / effectivePageStride()));
}
function totalPageCount() {
return Math.max(configuredPageCount, measuredPageCount());
}
function currentPageOffset() {
return Math.round(visiblePageIndex * effectivePageStride());
}
function reportProgression(fragment) {
var pageCount = totalPageCount();
var progression = pageCount <= 1 ? 0 : visiblePageIndex / Math.max(pageCount - 1, 1);
var lastProgression = progression;
window.webkit.messageHandlers.{{PROGRESSION_CHANGED_MESSAGE}}.postMessage({
progression: progression,
lastProgression: lastProgression,
fragment: fragment || null
});
}
function setVisiblePageIndex(pageIndex) {
if (isFixedLayoutDocument()) {
visiblePageIndex = 0;
return;
}
var pageCount = totalPageCount();
var maxPageIndex = Math.max(0, pageCount - 1);
var safePageIndex = Math.max(0, Math.min(maxPageIndex, Math.round(pageIndex || 0)));
visiblePageIndex = safePageIndex;
var content = paginationContent();
if (content) {
content.style.transform = 'translate3d(' + (-currentPageOffset()) + 'px, 0, 0)';
}
}
function scheduleRelayout() {
if (isFixedLayoutDocument()) { return; }
clearTimeout(relayoutTimer);
relayoutTimer = setTimeout(function() {
setVisiblePageIndex(visiblePageIndex);
reportProgression(null);
}, 60);
}
function pageIndexForElement(target) {
if (isFixedLayoutDocument()) { return 0; }
if (!target) { return 0; }
var rect = target.getBoundingClientRect();
var absoluteLeft = Math.max(0, rect.left + currentPageOffset());
return Math.max(0, Math.floor(absoluteLeft / effectivePageStride()));
}
function fragmentTarget(fragment) {
if (!fragment) { return null; }
var contexts = documentContexts(document, 0, 0);
for (var index = 0; index < contexts.length; index += 1) {
var context = contexts[index];
var target = context.doc.getElementById(fragment)
|| context.doc.querySelector('[name="' + fragment.replace(/"/g, '\\"') + '"]');
if (target) {
return {
context: context,
target: target
};
}
}
return null;
}
var storedHighlights = [];
var storedSearchPresentation = null;
function normalizeHref(rawHref) {
if (!rawHref) { return ''; }
var value = String(rawHref);
value = value.replace(/^.*?:\/\/[^/]+\//, '');
value = value.split('#')[0];
value = value.replace(/^\/+/, '');
try {
value = decodeURIComponent(value);
} catch (error) {
}
return value;
}
function clearHighlights() {
storedHighlights = [];
}
function setHighlights(items) {
storedHighlights = Array.isArray(items) ? items.slice() : [];
}
function setSearchPresentation(payload) {
storedSearchPresentation = payload || null;
}
function textNodes(doc) {
if (!doc || !doc.body) { return []; }
var walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT, {
acceptNode: function(node) {
if (!node || !node.nodeValue || !node.nodeValue.trim()) {
return NodeFilter.FILTER_REJECT;
}
var parent = node.parentNode;
if (!parent || !parent.nodeName) {
return NodeFilter.FILTER_REJECT;
}
var name = parent.nodeName.toLowerCase();
if (['script', 'style', 'noscript'].indexOf(name) >= 0) {
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
}
});
var nodes = [];
while (walker.nextNode()) {
nodes.push(walker.currentNode);
}
return nodes;
}
function documentContexts(rootDoc, baseOffsetX, baseOffsetY) {
var items = [];
if (!rootDoc) { return items; }
var offsetX = baseOffsetX || 0;
var offsetY = baseOffsetY || 0;
items.push({
doc: rootDoc,
href: normalizeHref(rootDoc.location && rootDoc.location.href),
offsetX: offsetX,
offsetY: offsetY
});
var frames = rootDoc.querySelectorAll ? rootDoc.querySelectorAll('iframe') : [];
frames.forEach(function(frame) {
try {
if (!frame.contentDocument) { return; }
var frameRect = frame.getBoundingClientRect();
documentContexts(
frame.contentDocument,
offsetX + frameRect.left,
offsetY + frameRect.top
).forEach(function(item) {
items.push(item);
});
} catch (error) {
}
});
return items;
}
var hookedDocuments = new WeakSet();
var hookedFrames = new WeakSet();
function selectionForDocument(doc) {
if (!doc) { return null; }
try {
var view = doc.defaultView || window;
return view.getSelection ? view.getSelection() : null;
} catch (error) {
return null;
}
}
function currentSelectionContext() {
var contexts = documentContexts(document, 0, 0);
for (var index = 0; index < contexts.length; index += 1) {
var context = contexts[index];
var selection = selectionForDocument(context.doc);
if (!selection || selection.rangeCount === 0 || selection.isCollapsed) {
continue;
}
var text = selection.toString ? selection.toString() : '';
if (!text || !text.trim()) {
continue;
}
return {
context: context,
selection: selection
};
}
return null;
}
function rectPayloadForRange(range, offsetX, offsetY) {
if (!range || range.collapsed) { return []; }
var rects = [];
Array.prototype.forEach.call(range.getClientRects(), function(rect) {
if (!rect || rect.width < 0.5 || rect.height < 0.5) { return; }
rects.push({
x: rect.left + (offsetX || 0),
y: rect.top + (offsetY || 0),
width: rect.width,
height: rect.height
});
});
return rects;
}
function collectHighlightDecorations() {
return storedHighlights.map(function(item, index) {
if (!item || !item.rangeInfo) { return null; }
var range = rangeFromInfo(item.rangeInfo);
var rects = rectPayloadForRange(range, 0, 0);
if (!rects.length) { return null; }
return {
key: item.id || ('highlight-' + index),
kind: item.style === 'underline' ? 'underline' : 'highlight',
color: item.color || '#F8E16C',
rangeInfo: item.rangeInfo,
rects: rects
};
}).filter(Boolean);
}
function collectSearchDecorations() {
if (!storedSearchPresentation || !storedSearchPresentation.keyword) {
return [];
}
var resources = new Map();
if (Array.isArray(storedSearchPresentation.resources)) {
storedSearchPresentation.resources.forEach(function(resource) {
resources.set(normalizeHref(resource.href), resource);
});
}
var keyword = String(storedSearchPresentation.keyword);
var lowerKeyword = keyword.toLowerCase();
var decorations = [];
documentContexts(document, 0, 0).forEach(function(context) {
var resourceState = resources.get(context.href);
if (!resourceState || resourceState.matchCount <= 0) {
return;
}
var activeIndex = typeof resourceState.activeLocalMatchIndex === 'number' ? resourceState.activeLocalMatchIndex : null;
var currentLocalIndex = 0;
var activeRect = null;
var contextStartIndex = decorations.length;
textNodes(context.doc).forEach(function(node) {
var source = node.nodeValue || '';
var lowerSource = source.toLowerCase();
var cursor = 0;
while (cursor < source.length) {
var foundIndex = lowerSource.indexOf(lowerKeyword, cursor);
if (foundIndex < 0) {
break;
}
var range = context.doc.createRange();
range.setStart(node, foundIndex);
range.setEnd(node, foundIndex + keyword.length);
var rects = rectPayloadForRange(range, context.offsetX, context.offsetY);
if (rects.length) {
var isActive = currentLocalIndex === activeIndex;
decorations.push({
key: context.href + ':' + currentLocalIndex,
kind: isActive ? 'activeSearch' : 'search',
rects: rects
});
if (isActive) {
activeRect = rects[0];
}
}
currentLocalIndex += 1;
cursor = foundIndex + keyword.length;
}
});
if (activeRect && !isFixedLayoutDocument()) {
var previousPageIndex = visiblePageIndex;
var activePageIndex = Math.max(0, Math.floor(Math.max(0, activeRect.x + currentPageOffset()) / effectivePageStride()));
setVisiblePageIndex(activePageIndex);
var deltaX = (activePageIndex - previousPageIndex) * effectivePageStride();
if (deltaX !== 0) {
for (var index = contextStartIndex; index < decorations.length; index += 1) {
decorations[index].rects = decorations[index].rects.map(function(rect) {
return {
x: rect.x - deltaX,
y: rect.y,
width: rect.width,
height: rect.height
};
});
}
}
}
});
return decorations;
}
function resolveDecorations() {
return {
highlights: collectHighlightDecorations(),
search: collectSearchDecorations()
};
}
function selectionPayload() {
var payloadContext = currentSelectionContext();
if (!payloadContext) {
return null;
}
var range = payloadContext.selection.getRangeAt(0);
var text = payloadContext.selection.toString();
if (!text || !text.trim()) { return null; }
var pageCount = totalPageCount();
var progression = pageCount <= 1 ? 0 : visiblePageIndex / Math.max(pageCount - 1, 1);
var lastProgression = progression;
return {
href: payloadContext.context.href || null,
text: text,
rangeInfo: serializeRange(range),
progression: progression,
lastProgression: lastProgression
};
}
var selectionTimer = null;
function notifySelectionChange() {
clearTimeout(selectionTimer);
selectionTimer = setTimeout(function() {
var payload = selectionPayload();
window.webkit.messageHandlers.{{SELECTION_CHANGED_MESSAGE}}.postMessage(payload);
}, 120);
}
function handleDocumentClick(event) {
// Check for image tap. Footnote images always show the note popup; regular
// images inside links are left to the link handler below.
var img = event.target;
while (img && img.tagName !== 'IMG') {
img = img.parentElement;
}
if (img && img.tagName === 'IMG') {
var src = img.getAttribute('src');
var classes = (img.getAttribute('class') || '').toLowerCase();
var alt = (img.getAttribute('alt') || '').trim();
var isFootnote = classes.indexOf('qqreader-footnote') >= 0 || alt.length > 0;
if (isFootnote) {
event.preventDefault();
event.stopPropagation();
var footnoteRect = img.getBoundingClientRect();
window.webkit.messageHandlers.{{FOOTNOTE_DID_TAP_MESSAGE}}.postMessage({
alt: alt,
rect: { x: footnoteRect.x, y: footnoteRect.y, width: footnoteRect.width, height: footnoteRect.height }
});
return;
}
// If a regular image is inside a link, let the link handler deal with it.
var linkParent = img.closest ? img.closest('a[href]') : null;
if (!linkParent) {
if (src) {
event.preventDefault();
event.stopPropagation();
var rect = img.getBoundingClientRect();
window.webkit.messageHandlers.{{IMAGE_DID_TAP_MESSAGE}}.postMessage({
src: src,
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height }
});
return;
}
}
}
var anchor = event.target.closest ? event.target.closest('a[href]') : null;
if (!anchor) { return; }
var href = anchor.getAttribute('href');
if (!href) { return; }
if (/^(https?:|mailto:|tel:)/i.test(href)) {
event.preventDefault();
window.webkit.messageHandlers.{{EXTERNAL_LINK_MESSAGE}}.postMessage({ url: href });
return;
}
event.preventDefault();
window.webkit.messageHandlers.{{INTERNAL_LINK_MESSAGE}}.postMessage({ href: href });
}
function installDocumentHooks(doc) {
if (!doc || hookedDocuments.has(doc)) { return; }
hookedDocuments.add(doc);
doc.addEventListener('selectionchange', notifySelectionChange);
doc.addEventListener('click', handleDocumentClick, true);
}
function installFrameHooks(rootDoc) {
if (!rootDoc || !rootDoc.querySelectorAll) { return; }
Array.prototype.forEach.call(rootDoc.querySelectorAll('iframe'), function(frame) {
if (hookedFrames.has(frame)) { return; }
hookedFrames.add(frame);
var hookFrameDocument = function() {
try {
if (!frame.contentDocument) { return; }
installDocumentHooks(frame.contentDocument);
installFrameHooks(frame.contentDocument);
} catch (error) {
}
};
frame.addEventListener('load', function() {
hookFrameDocument();
scheduleRelayout();
}, { passive: true });
hookFrameDocument();
});
}
installDocumentHooks(document);
installFrameHooks(document);
window.addEventListener('resize', function() {
if (isFixedLayoutDocument()) { return; }
setVisiblePageIndex(visiblePageIndex);
reportProgression(null);
}, { passive: true });
window.addEventListener('load', scheduleRelayout, { passive: true });
if (!isFixedLayoutDocument() && document.fonts && document.fonts.ready) {
document.fonts.ready.then(scheduleRelayout).catch(function() {});
}
if (!isFixedLayoutDocument()) {
Array.prototype.forEach.call(document.querySelectorAll('img, iframe, video'), function(node) {
node.addEventListener('load', scheduleRelayout, { passive: true });
node.addEventListener('error', scheduleRelayout, { passive: true });
});
}
window.RDEpubReaderBridge = {
applyPagination: function(styleText) {
if (isFixedLayoutDocument()) { return; }
if (window.RDInjectedCSS) {
window.RDInjectedCSS.setStyle('ss-reader-pagination', styleText, { includeFrames: false });
} else {
var style = document.getElementById('ss-reader-pagination');
if (!style) {
style = document.createElement('style');
style.id = 'ss-reader-pagination';
document.head.appendChild(style);
}
style.textContent = styleText;
}
ensurePaginationStructure();
installFrameHooks(document);
},
setPageMetrics: function(pageCount, pageStride) {
if (isFixedLayoutDocument()) { return; }
configuredPageCount = Math.max(1, Math.round(pageCount || 1));
configuredPageStride = Math.max(1, Number(pageStride) || configuredPageStride || 1);
setVisiblePageIndex(visiblePageIndex);
scheduleRelayout();
},
scrollToPage: function(pageIndex) {
if (isFixedLayoutDocument()) { return; }
setVisiblePageIndex(pageIndex);
reportProgression(null);
},
scrollToLocation: function(location, fallbackPageIndex, targetRangeInfo) {
if (targetRangeInfo) {
var highlightRange = rangeFromInfo(targetRangeInfo);
var highlightRects = rectPayloadForRange(highlightRange, 0, 0);
if (highlightRects.length) {
var highlightRect = highlightRects[0];
var highlightAbsoluteLeft = Math.max(0, highlightRect.x + currentPageOffset());
setVisiblePageIndex(Math.max(0, Math.floor(highlightAbsoluteLeft / effectivePageStride())));
reportProgression(location && location.fragment ? location.fragment : null);
return;
}
}
if (location && location.fragment) {
var resolvedTarget = fragmentTarget(location.fragment);
if (resolvedTarget) {
if (isFixedLayoutDocument()) {
reportProgression(location.fragment);
return;
}
var rect = resolvedTarget.target.getBoundingClientRect();
var absoluteLeft = Math.max(0, rect.left + resolvedTarget.context.offsetX + currentPageOffset());
setVisiblePageIndex(Math.max(0, Math.floor(absoluteLeft / effectivePageStride())));
reportProgression(location.fragment);
return;
}
}
var pageCount = totalPageCount();
var progression = location && typeof location.progression === 'number' ? location.progression : 0;
var derivedPageIndex = progression > 0 && pageCount > 1
? Math.round(progression * Math.max(pageCount - 1, 0))
: (fallbackPageIndex || 0);
this.scrollToPage(derivedPageIndex);
},
setHighlights: setHighlights,
clearHighlights: clearHighlights,
setSearchPresentation: setSearchPresentation,
resolveDecorations: resolveDecorations,
reportProgression: reportProgression,
selectionPayload: selectionPayload
};
})();
@@ -0,0 +1,266 @@
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<style>
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: {{BACKGROUND}}; }
body { position: relative; }
#ss-fixed-root {
position: absolute;
top: {{INSET_TOP}}px;
right: {{INSET_RIGHT}}px;
bottom: {{INSET_BOTTOM}}px;
left: {{INSET_LEFT}}px;
display: flex;
flex-direction: row;
align-items: stretch;
justify-content: center;
overflow: hidden;
}
.ss-fixed-viewport {
position: relative;
flex: 1 1 0;
min-width: 0;
min-height: 0;
overflow: hidden;
}
.ss-fixed-page {
position: absolute;
top: 50%;
width: 0;
height: 0;
border: 0;
background: transparent;
transform-origin: top left;
}
.ss-fixed-page[data-page-type="single"],
.ss-fixed-page[data-page-type="center"] {
left: 50%;
transform: translate(-50%, -50%);
}
.ss-fixed-page[data-page-type="left"] {
right: 0;
transform: translateY(-50%);
transform-origin: top right;
}
.ss-fixed-page[data-page-type="right"] {
left: 0;
transform: translateY(-50%);
transform-origin: top left;
}
</style>
</head>
<body>
<div id="ss-fixed-root">{{PANES}}</div>
<script>
(function() {
var Fit = { AUTO: 'auto', PAGE: 'page', WIDTH: 'width' };
var safeAreaInsets = { top: {{INSET_TOP}}, right: {{INSET_RIGHT}}, bottom: {{INSET_BOTTOM}}, left: {{INSET_LEFT}} };
var viewportSize = { width: {{VIEWPORT_WIDTH}}, height: {{VIEWPORT_HEIGHT}} };
var fit = '{{FIT_MODE}}';
var pendingFrames = 0;
var readySent = false;
function notifyReady() {
if (readySent) { return; }
readySent = true;
try {
window.webkit.messageHandlers.{{FIXED_LAYOUT_READY_MESSAGE}}.postMessage({ loaded: true });
} catch (error) {
}
}
function parsePageSizeFromViewportMetaTag(iframe) {
try {
var viewport = iframe.contentWindow.document.querySelector('meta[name="viewport"]');
if (!viewport) { return null; }
var regex = /(\w+) *= *([^\s,]+)/g;
var properties = {};
var match;
while ((match = regex.exec(viewport.content))) {
properties[match[1]] = match[2];
}
var width = Number.parseFloat(properties.width);
var height = Number.parseFloat(properties.height);
if (!width || !height) { return null; }
return { width: width, height: height };
} catch (error) {
return null;
}
}
function parseCssPixelValue(value) {
if (!value) { return 0; }
var match = String(value).match(/([0-9]+(?:\.[0-9]+)?)px?/);
return match ? Number.parseFloat(match[1]) : 0;
}
function sizeFromElement(element) {
if (!element) { return null; }
var width = parseCssPixelValue(element.style && element.style.width);
var height = parseCssPixelValue(element.style && element.style.height);
if (!width || !height) {
width = parseCssPixelValue(element.getAttribute && element.getAttribute('width'));
height = parseCssPixelValue(element.getAttribute && element.getAttribute('height'));
}
if (!width || !height) {
var rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null;
if (rect) {
width = width || rect.width;
height = height || rect.height;
}
}
if (width > 1 && height > 1) {
return { width: width, height: height };
}
return null;
}
function parsePageSizeFromDocumentBox(iframe) {
try {
var doc = iframe.contentWindow.document;
return sizeFromElement(doc.body) ||
sizeFromElement(doc.documentElement) ||
sizeFromElement(doc.querySelector('[id$="_hype_container"]')) ||
sizeFromElement(doc.querySelector('iframe')) ||
null;
} catch (error) {
return null;
}
}
function parsePageSizeFromNestedFrame(iframe) {
try {
var nestedFrame = iframe.contentWindow.document.querySelector('iframe');
if (!nestedFrame || !nestedFrame.contentWindow || !nestedFrame.contentWindow.document) {
return null;
}
return parsePageSizeFromViewportMetaTag(nestedFrame) ||
parsePageSizeFromDocumentBox(nestedFrame) ||
parsePageSizeFromEmbeddedImage(nestedFrame);
} catch (error) {
return null;
}
}
function parsePageSizeFromEmbeddedImage(iframe) {
try {
var img = iframe.contentWindow.document.querySelector('img');
if (!img || !img.naturalWidth || !img.naturalHeight) { return null; }
return { width: img.naturalWidth, height: img.naturalHeight };
} catch (error) {
return null;
}
}
function pageViewportSize(iframe) {
var viewport = iframe.closest('.ss-fixed-viewport');
if (!viewport) { return viewportSize; }
var width = Math.max(1, viewport.clientWidth);
var height = Math.max(1, viewport.clientHeight);
if (width <= 1 || height <= 1) {
return viewportSize;
}
return {
width: width,
height: height
};
}
function usesWidthFit(pageSize, localViewport) {
if (fit === Fit.WIDTH) {
return true;
}
if (fit !== Fit.AUTO) {
return false;
}
var widthRatio = localViewport.width / pageSize.width;
var heightRatio = localViewport.height / pageSize.height;
return widthRatio <= heightRatio;
}
function layoutPage(iframe) {
var pageSize = iframe.__ssPageSize;
if (!pageSize) { return; }
var pageType = iframe.dataset.pageType || 'single';
var localViewport = pageViewportSize(iframe);
iframe.style.width = pageSize.width + 'px';
iframe.style.height = pageSize.height + 'px';
var widthRatio = localViewport.width / pageSize.width;
var heightRatio = localViewport.height / pageSize.height;
var widthFit = usesWidthFit(pageSize, localViewport);
var scale = widthFit ? widthRatio : Math.min(widthRatio, heightRatio);
var scaledWidth = pageSize.width * scale;
var scaledHeight = pageSize.height * scale;
var offsetX, offsetY;
if (pageType === 'left') {
offsetX = localViewport.width - scaledWidth;
} else if (pageType === 'right') {
offsetX = 0;
} else {
offsetX = (localViewport.width - scaledWidth) / 2;
}
if (widthFit && scaledHeight > localViewport.height) {
offsetY = safeAreaInsets.top;
} else {
offsetY = (localViewport.height - scaledHeight) / 2;
offsetY += (safeAreaInsets.top - safeAreaInsets.bottom) / 2;
}
iframe.style.left = offsetX + 'px';
iframe.style.top = offsetY + 'px';
iframe.style.transform = 'scale(' + scale + ')';
}
function preparePage(iframe) {
pendingFrames += 1;
function finalizeLoad() {
pendingFrames = Math.max(0, pendingFrames - 1);
if (pendingFrames === 0) {
notifyReady();
}
}
function onLoad() {
iframe.__ssPageSize =
parsePageSizeFromViewportMetaTag(iframe) ||
parsePageSizeFromDocumentBox(iframe) ||
parsePageSizeFromNestedFrame(iframe) ||
parsePageSizeFromEmbeddedImage(iframe) ||
pageViewportSize(iframe);
layoutPage(iframe);
window.setTimeout(function() {
layoutPage(iframe);
}, 250);
finalizeLoad();
}
iframe.addEventListener('load', function() {
window.setTimeout(onLoad, 100);
});
iframe.addEventListener('error', function() {
iframe.__ssPageSize = pageViewportSize(iframe);
layoutPage(iframe);
finalizeLoad();
});
}
var pages = document.querySelectorAll('.ss-fixed-page');
Array.prototype.forEach.call(pages, preparePage);
if (pages.length === 0) {
notifyReady();
}
window.addEventListener('resize', function() {
Array.prototype.forEach.call(document.querySelectorAll('.ss-fixed-page'), layoutPage);
});
})();
</script>
</body>
</html>
@@ -0,0 +1,13 @@
(function() {
if (window.rangy) { return; }
window.rangy = {
initialized: true,
init: function() {
return window.rangy;
},
createRange: function(doc) {
return (doc || document).createRange();
}
};
})();
@@ -0,0 +1,93 @@
(function() {
if (!window.rangy) {
window.rangy = {};
}
if (window.rangy.serializeRange && window.rangy.deserializeRange) {
return;
}
function normalizeHref(rawHref) {
if (!rawHref) { return ''; }
var value = String(rawHref);
value = value.replace(/^.*?:\/\/[^/]+\//, '');
value = value.split('#')[0];
value = value.replace(/^\/+/, '');
try {
value = decodeURIComponent(value);
} catch (error) {
}
return value;
}
function nodePath(node) {
var path = [];
var current = node;
while (current && current !== current.ownerDocument) {
var parent = current.parentNode;
if (!parent) { break; }
var index = Array.prototype.indexOf.call(parent.childNodes, current);
path.unshift(index);
current = parent;
}
return path;
}
function nodeFromPath(doc, path) {
var current = doc;
for (var index = 0; index < path.length; index += 1) {
if (!current || !current.childNodes || current.childNodes.length <= path[index]) {
return null;
}
current = current.childNodes[path[index]];
}
return current;
}
function documentContexts(rootDoc) {
var items = [];
if (!rootDoc) { return items; }
items.push(rootDoc);
var frames = rootDoc.querySelectorAll ? rootDoc.querySelectorAll('iframe') : [];
Array.prototype.forEach.call(frames, function(frame) {
try {
if (!frame.contentDocument) { return; }
documentContexts(frame.contentDocument).forEach(function(item) {
items.push(item);
});
} catch (error) {
}
});
return items;
}
window.rangy.serializeRange = function(range, doc) {
var ownerDocument = doc || (range && range.startContainer && range.startContainer.ownerDocument) || document;
return JSON.stringify({
kind: 'dom-range',
documentHref: normalizeHref(ownerDocument.location && ownerDocument.location.href),
startPath: nodePath(range.startContainer),
startOffset: range.startOffset,
endPath: nodePath(range.endContainer),
endOffset: range.endOffset
});
};
window.rangy.deserializeRange = function(rangeInfo, rootDoc) {
try {
var payload = typeof rangeInfo === 'string' ? JSON.parse(rangeInfo) : rangeInfo;
var documentHref = normalizeHref(payload.documentHref);
var resolvedDocument = (documentContexts(rootDoc || document).find(function(candidate) {
return normalizeHref(candidate.location && candidate.location.href) === documentHref;
})) || (rootDoc || document);
var startNode = nodeFromPath(resolvedDocument, payload.startPath || []);
var endNode = nodeFromPath(resolvedDocument, payload.endPath || []);
if (!startNode || !endNode) { return null; }
var range = resolvedDocument.createRange();
range.setStart(startNode, payload.startOffset || 0);
range.setEnd(endNode, payload.endOffset || 0);
return range;
} catch (error) {
return null;
}
};
})();
@@ -0,0 +1,56 @@
/* 适配搜狗百科 bar 里的 icon 被染色 */
.header-home, .header-home:before, .header-logo, .loginBox, .header-search, .header-search:before, .header-more:before {
background-color: transparent !important;
}
/* 适配搜狗百科 某些透明的 div 被染色导致挡住图片 */
.abstract-img-none {
background: none !important;
}
/* 适配百度搜索图片丢失 */
.c-touchable-feedback-no-default * {
background-color: transparent !important;
}
img, video {
z-index: 1 !important;
}
/*背景纯黑*/
*, *:before, *:after {
background-color: rgba(0, 0, 0, 1) !important;
}
.wr-business-container,
.wr-business-container *,
.wr-business-container *:before,
.wr-business-container *:after {
background-color: rgb(28, 28, 29) !important;
}
/*背景颜色和一般字体颜色*/
div, h1, h2, h3, h4, h5, h6, p, body, em, html, link, textarea, form, select, input, span, button, em, menu, aside, table, tr, td, nav, dl, dt, dd, amp-iframe, main, section {
color: rgba(180, 180, 182, 1) !important;
border-color: #555555 !important;
text-shadow: 0 0 0 #000;
}
/*超链接*/
a {
color: rgba(84, 127, 176, 1) !important;
}
blockquote {
color : rgb(218, 220, 224);
background-color : rgb(10, 14, 18) !important;
border-left: 1px solid rgba(116, 120, 124, 1);
}
img {
border: none !important;
}
ul li:before, ol li:before {
background-color: rgba(196, 200, 204, 1) !important;
}
@@ -0,0 +1,221 @@
/* this file is processed with xxd via a build rule and embedded in library */
/* these styles come from Safari */
/* note that comments are only permitted before selectors and before the styles */
/* DO NOT fiddle with this file if you want to have your own styles,
pass your own stylesheet via the option parameter to override these defaults */
head {
display:none;
}
title {
display:none;
}
style {
display:none;
}
link {
display: none;
}
meta {
display: none;
}
script {
display: none;
}
html {
display:block;
margin:0;
padding:0;
}
body {
display:block;
font-size:16px;
margin:0;
padding:0;
}
article,aside,footer,header,hgroup,nav,section {
display:block;
}
p {
display:block;
margin:0;
}
img {
margin:0;
}
ul,ol,menu,dir {
display:block;
margin:1em 0 1em 0;
padding-left:24px;
}
ul {
list-style-type:disc;
}
ol {
list-style-type:decimal;
}
li {
display:list-item;
}
ul ul, ol ul {
list-style-type: circle;
}
ol ol ul, ol ul ul, ul ol ul, ul ul ul {
list-style-type: square;
}
code {
font-family:Courier;
}
pre, xmp, plaintext, listing {
display: block;
font-family: monospace;
white-space: pre;
margin: 1em 0;
}
a {
color:#2262A3;
text-decoration:underline;
}
a:active {
color:#2262A3;
}
center {
text-align:center;
display:block;
}
strong,b {
font-weight:bold;
}
i,em {
font-style:italic;
}
u {
text-decoration:underline;
}
big {
font-size:bigger;
}
small {
font-size:smaller;
}
sub {
font-size:smaller;
vertical-align:sub;
}
sup {
font-size:smaller;
vertical-align:super;
}
s,strike,del {
text-decoration:line-through;
}
tt,code,kbd,samp {
font-family:monospace;
}
pre,xmp,plaintext,listing {
display:block;
font-family:monospace;
white-space:pre;
margin-top:1em;
margin-right:0;
margin-bottom:1em;
}
pre {
background-color:rgba(0,0,0,.05);
padding-top:1em;
padding-bottom:1em;
border-radius:0.3em;
}
h1 {
display:block;
font-size:1.5em;
font-weight: normal;
}
h2 {
display:block;
font-size:1.4em;
margin-top: 0.83em;
}
h3 {
display:block;
font-size:1.3em;
margin-top: 1em;
}
h4 {
display:block;
font-size:1.2em;
margin-top: 1.33em;
}
h5 {
display:block;
font-size:1.1em;
margin-top: 1.67em;
}
h6 {
display:block;
font-size:1em;
margin-top: 2.33em;
}
div {
display: block;
}
hr {
display: block;
margin:0.5em auto 0.5em auto;
border-style: inset;
border-width: 1px;
}
table {
display: table;
border-collapse: separate;
border-spacing: 2px;
border-color: gray;
}
blockquote {
display: block;
}
@@ -0,0 +1,113 @@
/* <pre>代码块,注意必须写font-weight使字体生效 */
pre {
font-family: "Menlo";
font-weight: normal;
line-height: 1.5em;
}
/*版权信息*/
.copyRightTitle {
color: black;
font-size: 1.5em;
font-family: "Source Han Serif CN";
font-weight: normal;
}
/*图片说明文字*/
.eepub-single-image-title {
font-size: 0.75em;
text-align: center;
line-height: 1.4em;
color: rgba(0, 0, 0, 0.9);
margin: 0.2em 0.4em 1em 0.4em;
font-weight: normal;
}
/*标题*/
.firstTitle, h1.firstTitle {
font-size: 1.5em;
font-weight: bold;
line-height: 1.25em;
}
.secondTitle, h2.secondTitle {
font-size: 1.4em;
font-weight: bold;
line-height: 1.35em;
}
.thirdTitle, h3.thirdTitle {
font-size: 1.3em;
font-weight: bold;
line-height: 1.5em;
}
.fourthTitle, h4.fourthTitle {
font-size: 1.2em;
font-weight: bold;
line-height: 1.65em;
}
.fifthTitle, h5.fifthTitle {
font-size: 1.1em;
font-weight: bold;
line-height: 1.85em;
}
.sixthTitle, h6.sixthTitle {
font-size: 1em;
font-weight: bold;
line-height: 2em;
}
/*首字加大*/
/*浮动元素有默认的margin,所以这里会修复一下*/
.ftext {
float: left;
margin: 0em;
font-size: 2.38em;
font-weight: normal;
}
/*引用内容*/
.conQuot {
font-weight: normal;
margin: 0em 0em 0.2em 0em;
}
/*标题下来可能会有一行subHead*/
.subHead{
text-indent: 2em;
}
pre, pre span, pre code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size:.7em!important;
}
.bodyPic {
wr-vertical-center-style: 2;
}
.qrbodyPic {
page-break-inside: avoid;
wr-vertical-center-style: 2;
}
/* 注标图 */
.qqreader-footnote {
width: 1em;
}
/* 私有垂直居中类 */
.wr-vertical-center {
wr-vertical-center-style: 1 !important;
}
/* 翻译 */
.wr-translation {
line-height: 1.7em !important;
}
/* 章节结尾工具 */
.book-chapter-tool {
display: block;
height: 78px;
width: 100%;
margin-top: 24px;
}
@@ -0,0 +1,171 @@
/* <pre>代码块,注意必须写font-weight使字体生效 */
pre {
font-family: "Menlo";
font-weight: normal;
line-height: 1.5em;
}
/*版权信息*/
.copyRightTitle {
color: black;
font-size: 1.5em;
font-family: "Source Han Serif CN";
font-weight: normal;
}
/*图片说明文字*/
.eepub-single-image-title {
font-size: 0.75em;
text-align: center;
line-height: 1.4em;
color: rgba(0, 0, 0, 0.9);
margin: 0.2em 0.4em 1em 0.4em;
font-family: "FZFSJW--GB1-0";
font-weight: normal;
}
/*标题*/
.firstTitle, h1.firstTitle {
font-size: 1.5em;
font-family: "Source Han Serif CN";
font-weight: bold;
line-height: 1.25em;
}
.secondTitle, h2.secondTitle {
font-size: 1.4em;
font-family: "Source Han Serif CN";
font-weight: bold;
line-height: 1.35em;
}
.thirdTitle, h3.thirdTitle {
font-size: 1.3em;
font-family: "Source Han Serif CN";
font-weight: bold;
line-height: 1.5em;
}
.fourthTitle, h4.fourthTitle {
font-size: 1.2em;
font-family: "Source Han Serif CN";
font-weight: bold;
line-height: 1.65em;
}
.fifthTitle, h5.fifthTitle {
font-size: 1.1em;
font-family: "Source Han Serif CN";
font-weight: bold;
line-height: 1.85em;
}
.sixthTitle, h6.sixthTitle {
font-size: 1em;
font-family: "Source Han Serif CN";
font-weight: bold;
line-height: 2em;
}
/*首字加大*/
/*浮动元素有默认的margin,所以这里会修复一下*/
.ftext {
float: left;
margin: 0em;
font-size: 2.38em;
font-weight: normal;
}
/*引用内容*/
.conQuot {
font-family: "FZFSJW--GB1-0";
font-weight: normal;
margin: 0em 0em 0.2em 0em;
}
/*标题下来可能会有一行subHead*/
.subHead{
text-indent: 2em;
}
pre, pre span, pre code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size:.7em!important;
}
.bodyPic {
wr-vertical-center-style: 2;
}
.qrbodyPic {
page-break-inside: avoid;
wr-vertical-center-style: 2;
}
/* 注标图 */
.qqreader-footnote {
width: 1em;
}
/* 翻译 */
.wr-translation {
line-height: 1.7em !important;
}
/*-------------------- 小文章相关 ----------------------*/
/*epub-custom-rule-6 如果 class="weread-page-relate" 在开头,需要把上一页末尾一行移到这一页*/
.weread-page-relate {
weread-page-relate:true;
}
/*epub-custom-rule-29 小文章打赏的样式*/
.chapter-reward {
display: block;
height: 120px;
width: 100%;
margin-top: 24px;
}
/*epub-custom-rule-7 小文章工具栏标签的样式*/
.chapter-tool {
display: block;
height: 140px;
width: 100%;
margin-top: 24px;
}
/* 章节结尾工具 */
.book-chapter-tool {
display: block;
height: 78px;
width: 100%;
margin-top: 24px;
}
/* 调试好样式后和安卓同步,交给后台随小文章 css 下发,并把下面的样式从replace.css 删除 */
/* 安卓的re_bookItem是通过原生view留出上下空间的,但是iOS是通过css来控制 */
.re_bookItem{
display: block;
margin: 18px 0 18px 0;
}
p {
text-align:justify;
}
img[data-image-size="large"] {
width: 100%;
}
/* 文集公众号文章不支持控件的样式 */
.unsupported_iframe {
border-radius: 4px;
border: 1px solid #ffcdc0;
background: #fee;
padding: 12px 0px;
color: #ff8d8d;
text-align: center;
font-size: 14px;
}
/* 私有垂直居中类 */
.wr-vertical-center {
wr-vertical-center-style: 1 !important;
}