diff --git a/package.json b/package.json index 76b2d8c56..bffc8e138 100644 --- a/package.json +++ b/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", @@ -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", diff --git a/src/layout.js b/src/layout.js index 4f16a0f1d..24ad20b86 100644 --- a/src/layout.js +++ b/src/layout.js @@ -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; @@ -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; diff --git a/src/managers/default/index.js b/src/managers/default/index.js index 1944889ad..a11aa67b5 100644 --- a/src/managers/default/index.js +++ b/src/managers/default/index.js @@ -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); } @@ -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); @@ -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")) { @@ -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); @@ -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") { @@ -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