mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
commit
ca48f604bf
7 changed files with 49 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "epubjs",
|
"name": "epubjs",
|
||||||
"version": "0.3.22",
|
"version": "0.3.24",
|
||||||
"description": "Parse and Render Epubs",
|
"description": "Parse and Render Epubs",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"jsnext:main": "src/index.js",
|
"jsnext:main": "src/index.js",
|
||||||
|
|
|
@ -735,8 +735,8 @@ class Contents {
|
||||||
this.css("background-color", "transparent");
|
this.css("background-color", "transparent");
|
||||||
}
|
}
|
||||||
|
|
||||||
mapPage(cfiBase, start, end) {
|
mapPage(cfiBase, layout, start, end, dev) {
|
||||||
var mapping = new Mapping();
|
var mapping = new Mapping(layout, dev);
|
||||||
|
|
||||||
return mapping.page(this, cfiBase, start, end);
|
return mapping.page(this, cfiBase, start, end);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
*/
|
*/
|
||||||
class Layout {
|
class Layout {
|
||||||
constructor(settings) {
|
constructor(settings) {
|
||||||
|
this.settings = settings;
|
||||||
this.name = settings.layout || "reflowable";
|
this.name = settings.layout || "reflowable";
|
||||||
this._spread = (settings.spread === "none") ? false : true;
|
this._spread = (settings.spread === "none") ? false : true;
|
||||||
this._minSpreadWidth = settings.minSpreadWidth || 800;
|
this._minSpreadWidth = settings.minSpreadWidth || 800;
|
||||||
|
@ -30,6 +31,20 @@ class Layout {
|
||||||
this.columnWidth = 0;
|
this.columnWidth = 0;
|
||||||
this.gap = 0;
|
this.gap = 0;
|
||||||
this.divisor = 1;
|
this.divisor = 1;
|
||||||
|
|
||||||
|
this.props = {
|
||||||
|
name: this.name,
|
||||||
|
spread: this._spread,
|
||||||
|
flow: this._flow,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
spreadWidth: 0,
|
||||||
|
delta: 0,
|
||||||
|
columnWidth: 0,
|
||||||
|
gap: 0,
|
||||||
|
divisor: 1
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,6 +59,7 @@ class Layout {
|
||||||
} else {
|
} else {
|
||||||
this._flow = "paginated";
|
this._flow = "paginated";
|
||||||
}
|
}
|
||||||
|
this.props.flow = this._flow;
|
||||||
}
|
}
|
||||||
return this._flow;
|
return this._flow;
|
||||||
}
|
}
|
||||||
|
@ -56,11 +72,16 @@ class Layout {
|
||||||
*/
|
*/
|
||||||
spread(spread, min) {
|
spread(spread, min) {
|
||||||
|
|
||||||
this._spread = (spread === "none") ? false : true;
|
if (spread) {
|
||||||
|
this._spread = (spread === "none") ? false : true;
|
||||||
|
this.props.spread = this._spread;
|
||||||
|
}
|
||||||
|
|
||||||
if (min >= 0) {
|
if (min >= 0) {
|
||||||
this._minSpreadWidth = min;
|
this._minSpreadWidth = min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._spread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,6 +142,15 @@ class Layout {
|
||||||
this.columnWidth = colWidth;
|
this.columnWidth = colWidth;
|
||||||
this.gap = gap;
|
this.gap = gap;
|
||||||
this.divisor = divisor;
|
this.divisor = divisor;
|
||||||
|
|
||||||
|
this.props.width = width;
|
||||||
|
this.props.height = _height;
|
||||||
|
this.props.spreadWidth = spreadWidth;
|
||||||
|
this.props.delta = delta;
|
||||||
|
|
||||||
|
this.props.columnWidth = colWidth;
|
||||||
|
this.props.gap = gap;
|
||||||
|
this.props.divisor = divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -442,7 +442,7 @@ class DefaultViewManager {
|
||||||
endA = startA + (container.top - visible[0].position().bottom);
|
endA = startA + (container.top - visible[0].position().bottom);
|
||||||
|
|
||||||
startB = (container.top - visible[last].position().top) + offset;
|
startB = (container.top - visible[last].position().top) + offset;
|
||||||
endB = startB + pageHeight;
|
endB = pageHeight - startB;
|
||||||
|
|
||||||
startPage = this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA)
|
startPage = this.mapping.page(visible[0].contents, visible[0].section.cfiBase, startA, endA)
|
||||||
endPage = this.mapping.page(visible[last].contents, visible[last].section.cfiBase, startB, endB);
|
endPage = this.mapping.page(visible[last].contents, visible[last].section.cfiBase, startB, endB);
|
||||||
|
@ -629,7 +629,7 @@ class DefaultViewManager {
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
this.updateLayout();
|
this.updateLayout();
|
||||||
|
|
||||||
this.mapping = new Mapping(this.layout);
|
this.mapping = new Mapping(this.layout.props);
|
||||||
// this.manager.layout(this.layout.format);
|
// this.manager.layout(this.layout.format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import EpubCFI from "./epubcfi";
|
||||||
class Mapping {
|
class Mapping {
|
||||||
constructor(layout, dev) {
|
constructor(layout, dev) {
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
this.horizontal = (this.layout.flow() === "paginated") ? true : false;
|
this.horizontal = (this.layout.flow === "paginated") ? true : false;
|
||||||
this._dev = dev;
|
this._dev = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,14 +67,15 @@ class Mapping {
|
||||||
findRanges(view){
|
findRanges(view){
|
||||||
var columns = [];
|
var columns = [];
|
||||||
var scrollWidth = view.contents.scrollWidth();
|
var scrollWidth = view.contents.scrollWidth();
|
||||||
var count = this.layout.count(scrollWidth);
|
var spreads = Math.ceil( scrollWidth / this.layout.spreadWidth);
|
||||||
var column = this.layout.column;
|
var count = spreads * this.layout.divisor;
|
||||||
|
var columnWidth = this.layout.columnWidth;
|
||||||
var gap = this.layout.gap;
|
var gap = this.layout.gap;
|
||||||
var start, end;
|
var start, end;
|
||||||
|
|
||||||
for (var i = 0; i < count.pages; i++) {
|
for (var i = 0; i < count.pages; i++) {
|
||||||
start = (column + gap) * i;
|
start = (columnWidth + gap) * i;
|
||||||
end = (column * (i+1)) + (gap * i);
|
end = (columnWidth * (i+1)) + (gap * i);
|
||||||
columns.push({
|
columns.push({
|
||||||
start: this.findStart(view.document.body, start, end),
|
start: this.findStart(view.document.body, start, end),
|
||||||
end: this.findEnd(view.document.body, start, end)
|
end: this.findEnd(view.document.body, start, end)
|
||||||
|
|
|
@ -431,7 +431,7 @@ class Rendition {
|
||||||
this._layout = new Layout(settings);
|
this._layout = new Layout(settings);
|
||||||
this._layout.spread(settings.spread, this.settings.minSpreadWidth);
|
this._layout.spread(settings.spread, this.settings.minSpreadWidth);
|
||||||
|
|
||||||
this.mapping = new Mapping(this._layout);
|
this.mapping = new Mapping(this._layout.props);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.manager && this._layout) {
|
if (this.manager && this._layout) {
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
export const requestAnimationFrame = (typeof window != "undefined") ? (window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame) : false;
|
export const requestAnimationFrame = (typeof window != "undefined") ? (window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame) : false;
|
||||||
|
const ELEMENT_NODE = 1;
|
||||||
|
const TEXT_NODE = 3;
|
||||||
|
const COMMENT_NODE = 8;
|
||||||
|
const DOCUMENT_NODE = 9;
|
||||||
|
|
||||||
export function isElement(obj) {
|
export function isElement(obj) {
|
||||||
return !!(obj && obj.nodeType == 1);
|
return !!(obj && obj.nodeType == 1);
|
||||||
|
@ -242,11 +246,11 @@ export function indexOfNode(node, typeId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function indexOfTextNode(textNode) {
|
export function indexOfTextNode(textNode) {
|
||||||
return indexOfNode(textNode, Node.TEXT_NODE);
|
return indexOfNode(textNode, TEXT_NODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function indexOfElementNode(elementNode) {
|
export function indexOfElementNode(elementNode) {
|
||||||
return indexOfNode(elementNode, Node.ELEMENT_NODE);
|
return indexOfNode(elementNode, ELEMENT_NODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isXml(ext) {
|
export function isXml(ext) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue