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

Fix navigation with proper fraction #1128

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
14 changes: 7 additions & 7 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "epubjs",
"version": "0.3.88",
"name": "epubjs-myh",
"version": "0.3.93",
"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
4 changes: 2 additions & 2 deletions src/layout.js
Expand Up @@ -100,7 +100,7 @@ class Layout {
* @param {number} _height height of the rendering
* @param {number} _gap width of the gap between columns
*/
calculate(_width, _height, _gap){
calculate(_width, _height, _gap, axis){

var divisor = 1;
var gap = _gap || 0;
Expand All @@ -110,7 +110,7 @@ class Layout {
var width = _width;
var height = _height;

var section = Math.floor(width / 12);
var section = Math.floor((axis === 'vertical' ? height : width) / 12);

var columnWidth;
var spreadWidth;
Expand Down
22 changes: 17 additions & 5 deletions src/managers/default/index.js
Expand Up @@ -343,6 +343,12 @@ class DefaultViewManager {
if (distX + this.layout.delta > this.container.scrollWidth) {
distX = this.container.scrollWidth - this.layout.delta;
}

distY = Math.floor(offset.top / this.layout.delta) * this.layout.delta;

if (distY + this.layout.delta > this.container.scrollHeight) {
distY = this.container.scrollHeight - this.layout.delta;
}
}
this.scrollTo(distX, distY, true);
}
Expand Down Expand Up @@ -451,7 +457,9 @@ class DefaultViewManager {
this.scrollLeft = this.container.scrollLeft;

if (this.settings.rtlScrollType === "default"){
left = this.container.scrollLeft;
this.scrollLeft = Math.floor(this.container.scrollLeft);
// this.container.scrollLeft could has fractional part.
left = Math.floor(this.container.scrollLeft);

if (left > 0) {
this.scrollBy(this.layout.delta, 0, true);
Expand Down Expand Up @@ -486,6 +494,7 @@ class DefaultViewManager {

if(next) {
this.clear();
this.updateLayout();

let forceRight = false;
if (this.layout.name === "pre-paginated" && this.layout.divisor === 2 && next.properties.includes("page-spread-right")) {
Expand Down Expand Up @@ -559,9 +568,10 @@ class DefaultViewManager {

} else if (this.isPaginated && this.settings.axis === "vertical") {

this.scrollTop = this.container.scrollTop;
this.scrollTop = Math.floor(this.container.scrollTop);

let top = this.container.scrollTop;
// this.container.scrollTop could has fractional part.
let top = Math.floor(this.container.scrollTop);

if(top > 0) {
this.scrollBy(0, -(this.layout.height), true);
Expand All @@ -577,6 +587,7 @@ class DefaultViewManager {

if(prev) {
this.clear();
this.updateLayout();

let forceRight = false;
if (this.layout.name === "pre-paginated" && this.layout.divisor === 2 && typeof prev.prev() !== "object") {
Expand Down Expand Up @@ -920,12 +931,13 @@ class DefaultViewManager {
this._stageSize = this.stage.size();

if(!this.isPaginated) {
this.layout.calculate(this._stageSize.width, this._stageSize.height);
this.layout.calculate(this._stageSize.width, this._stageSize.height, undefined, this.settings.axis);
} else {
this.layout.calculate(
this._stageSize.width,
this._stageSize.height,
this.settings.gap
this.settings.gap,
this.settings.axis
);

// Set the look ahead offset for what is visible
Expand Down