Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page navigation with n pages #1152

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b7bb95d
* Fix moveTo for vertical writing mode.
MrMYHuang Sep 5, 2020
c592261
* Fix a layout update bug after crossing a section boundary.
MrMYHuang Sep 6, 2020
86f7370
* Update version.
MrMYHuang Sep 6, 2020
0450803
Merge remote-tracking branch 'origin/UpdateLayoutAcrossSection'
MrMYHuang Sep 6, 2020
c48d34c
* Update version.
MrMYHuang Sep 16, 2020
84c020a
* Fix top and bottom gap calculations for vertical writing mode.
MrRogerHuang Sep 16, 2020
92d93c4
* Update version.
MrRogerHuang Sep 16, 2020
8fbbd7e
* Fix a gap update bug after scrolling from one section to another se…
MrRogerHuang Sep 17, 2020
7e4f7b7
* Update version.
MrRogerHuang Sep 17, 2020
9baec61
* Fix page navigations for some layout modes.
MrRogerHuang Sep 18, 2020
90305cc
* Use fixed gaps to workaround complex layout updating across sections.
MrRogerHuang Sep 18, 2020
8ff03f0
* Fix locationOf in case of range is an empty string.
MrRogerHuang Sep 18, 2020
8714070
* Workaround a navigation problem between sections with invalid highl…
MrRogerHuang Sep 18, 2020
1b4b0c2
* Add an option scrollbarWidth to control reserved space between epub…
MrMYHuang Sep 20, 2020
1e92580
* Use default value if scrollbarWidth is undefined.
MrRogerHuang Sep 22, 2020
af88da4
* Export EVENTS.
MrMYHuang Oct 2, 2020
838c5b9
* Add vertical writing mode support for paginatedLocation.
MrMYHuang Oct 3, 2020
5034024
* Fix bugs for paginatedLocation for vertical writing modes.
MrMYHuang Oct 4, 2020
c583262
* Add comments.
MrMYHuang Oct 4, 2020
4b6eb07
* Fix scrollbarWidth bugs for layout size.
MrMYHuang Oct 13, 2020
41b1bf2
* Fix increasing scrolling error of scrollBy by compensation.
MrRogerHuang Oct 23, 2020
7b3ad0d
* Fix bugs.
MrRogerHuang Oct 23, 2020
ec0fa06
* prev and next support n pages.
MrMYHuang Nov 22, 2020
d3436bc
Merge remote-tracking branch 'origin/CompensateScrollByError'
MrMYHuang Nov 22, 2020
019225b
* Fix Typescript optional types.
MrMYHuang Nov 22, 2020
c9bd3ad
* Fix a copy and paste error.
MrRogerHuang Dec 4, 2020
af9d38f
* Remove padding depending on width.
MrRogerHuang Dec 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "epubjs",
"version": "0.3.88",
"name": "epubjs-myh",
"version": "0.3.111",
"description": "Parse and Render Epubs",
"main": "lib/index.js",
"module": "src/index.js",
Expand All @@ -16,15 +16,15 @@
"docs:md": "documentation build src/epub.js -f md -o documentation/md/API.md",
"lint": "eslint -c .eslintrc.js src; exit 0",
"start": "webpack-dev-server --inline --d",
"build": "NODE_ENV=production webpack --progress",
"minify": "NODE_ENV=production MINIMIZE=true webpack --progress",
"legacy": "NODE_ENV=production LEGACY=true webpack --progress",
"productionLegacy": "NODE_ENV=production MINIMIZE=true LEGACY=true webpack --progress",
"build": "set NODE_ENV=production && webpack --progress",
"minify": "set NODE_ENV=production && set MINIMIZE=true && webpack --progress",
"legacy": "set NODE_ENV=production && set LEGACY=true && webpack --progress",
"productionLegacy": "set NODE_ENV=production && set MINIMIZE=true && set LEGACY=true && webpack --progress",
"compile": "babel -d lib/ src/",
"watch": "babel --watch -d lib/ src/",
"prepare": "npm run compile && npm run build && npm run minify && npm run legacy && npm run productionLegacy"
},
"author": "fchasen@gmail.com",
"author": "myh@live.com",
"license": "BSD-2-Clause",
"devDependencies": {
"@babel/cli": "^7.10.1",
Expand Down
6 changes: 4 additions & 2 deletions src/contents.js
Expand Up @@ -655,7 +655,9 @@ class Contents {
console.error(e, e.stack);
}
} else {
position = range.getBoundingClientRect();
// range.toString() might be an empty string and range.getBoundingClientRect() returns a all-zeros position.
// Thus, we use the parent element containing the range to get a valid bounding rect.
position = range.startContainer.parentElement.getBoundingClientRect();
}
}
}
Expand Down Expand Up @@ -1025,7 +1027,7 @@ class Contents {
if (width >= 0) {
this.width(width);
viewport.width = width;
this.css("padding", "0 "+(width/12)+"px");
//this.css("padding", "0 "+(width/12)+"px");
}

if (height >= 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -4,12 +4,14 @@ import Rendition from "./rendition";
import Contents from "./contents";
import Layout from "./layout";
import ePub from "./epub";
import { EVENTS } from "./utils/constants";

export default ePub;
export {
Book,
EpubCFI,
Rendition,
Contents,
Layout
Layout,
EVENTS,
};
21 changes: 19 additions & 2 deletions src/layout.js
Expand Up @@ -103,18 +103,21 @@ class Layout {
calculate(_width, _height, _gap){

var divisor = 1;
var gap = _gap || 0;
var gap = _gap || 20;

//-- Check the width and create even width columns
// var fullWidth = Math.floor(_width);
var width = _width;
var height = _height;

var section = Math.floor(width / 12);
//var section = Math.floor(width / 12);

var columnWidth;
var columnHeight;
var spreadWidth;
var spreadHeight;
var pageWidth;
var pageHeight;
var delta;

if (this._spread && width >= this._minSpreadWidth) {
Expand All @@ -123,9 +126,11 @@ class Layout {
divisor = 1;
}

/*
if (this.name === "reflowable" && this._flow === "paginated" && !(_gap >= 0)) {
gap = ((section % 2 === 0) ? section : section - 1);
}
*/

if (this.name === "pre-paginated" ) {
gap = 0;
Expand All @@ -138,26 +143,35 @@ class Layout {
// gap = gap / divisor;
columnWidth = (width / divisor) - gap;
pageWidth = columnWidth + gap;
columnHeight = (height / divisor) - gap;
pageHeight = columnHeight + gap;
} else {
columnWidth = width;
pageWidth = width;
columnHeight = height;
pageHeight = height;
}

if (this.name === "pre-paginated" && divisor > 1) {
width = columnWidth;
height = columnHeight;
}

spreadWidth = (columnWidth * divisor) + gap;
spreadHeight = (columnHeight * divisor) + gap;

delta = width;

this.width = width;
this.height = height;
this.spreadWidth = spreadWidth;
this.pageWidth = pageWidth;
this.spreadHeight = spreadHeight;
this.pageHeight = pageHeight;
this.delta = delta;

this.columnWidth = columnWidth;
this.columnHeight = columnHeight;
this.gap = gap;
this.divisor = divisor;

Expand All @@ -175,9 +189,12 @@ class Layout {
width,
height,
spreadWidth,
spreadHeight,
pageWidth,
pageHeight,
delta,
columnWidth,
columnHeight,
gap,
divisor
});
Expand Down