9,155 changes: 0 additions & 9,155 deletions libs/jszip/jszip.js

This file was deleted.

14 changes: 0 additions & 14 deletions libs/jszip/jszip.min.js

This file was deleted.

632 changes: 0 additions & 632 deletions libs/url/url-polyfill.js

This file was deleted.

18,916 changes: 18,827 additions & 89 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epubjs",
"version": "0.3.88",
"version": "0.3.89",
"description": "Parse and Render Epubs",
"main": "lib/index.js",
"module": "src/index.js",
Expand Down Expand Up @@ -56,13 +56,13 @@
},
"dependencies": {
"@types/localforage": "0.0.34",
"@xmldom/xmldom": "^0.7.5",
"core-js": "^3.6.5",
"event-emitter": "^0.3.5",
"jszip": "^3.4.0",
"localforage": "^1.7.3",
"lodash": "^4.17.15",
"marks-pane": "^1.0.9",
"path-webpack": "0.0.3",
"xmldom": "^0.3.0"
"path-webpack": "0.0.3"
}
}
2 changes: 1 addition & 1 deletion src/archive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {defer, isXml, parse} from "./utils/core";
import request from "./utils/request";
import mime from "../libs/mime/mime";
import mime from "./utils/mime";
import Path from "./utils/path";
import JSZip from "jszip/dist/jszip";

Expand Down
2 changes: 1 addition & 1 deletion src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class Book {
/**
* Find a DOM Range for a given CFI Range
* @param {EpubCFI} cfiRange a epub cfi range
* @return {Range}
* @return {Promise}
*/
getRange(cfiRange) {
var cfi = new EpubCFI(cfiRange);
Expand Down
6 changes: 4 additions & 2 deletions src/managers/continuous/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ContinuousViewManager extends DefaultViewManager {
width: undefined,
height: undefined,
snap: false,
afterScrolledTimeout: 10
afterScrolledTimeout: 10,
allowScriptedContent: false
});

extend(this.settings, options.settings || {});
Expand All @@ -38,7 +39,8 @@ class ContinuousViewManager extends DefaultViewManager {
layout: this.layout,
width: 0,
height: 0,
forceEvenPages: false
forceEvenPages: false,
allowScriptedContent: this.settings.allowScriptedContent
};

this.scrollTop = 0;
Expand Down
34 changes: 29 additions & 5 deletions src/managers/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class DefaultViewManager {
writingMode: undefined,
flow: "scrolled",
ignoreClass: "",
fullsize: undefined
fullsize: undefined,
allowScriptedContent: false
});

extend(this.settings, options.settings || {});
Expand All @@ -39,7 +40,8 @@ class DefaultViewManager {
method: this.settings.method, // srcdoc, blobUrl, write
width: 0,
height: 0,
forceEvenPages: true
forceEvenPages: true,
allowScriptedContent: this.settings.allowScriptedContent
};

this.rendered = false;
Expand Down Expand Up @@ -277,7 +279,8 @@ class DefaultViewManager {

if(target) {
let offset = visible.locationOf(target);
this.moveTo(offset);
let width = visible.width();
this.moveTo(offset, width);
}

displaying.resolve();
Expand All @@ -298,7 +301,8 @@ class DefaultViewManager {
// Move to correct place within the section, if needed
if(target) {
let offset = view.locationOf(target);
this.moveTo(offset);
let width = view.width();
this.moveTo(offset, width);
}

}.bind(this), (err) => {
Expand Down Expand Up @@ -331,7 +335,7 @@ class DefaultViewManager {
this.emit(EVENTS.MANAGERS.RESIZE, view.section);
}

moveTo(offset){
moveTo(offset, width){
var distX = 0,
distY = 0;

Expand All @@ -343,6 +347,21 @@ 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;
}
}
if(this.settings.direction === 'rtl'){
/***
the `floor` function above (L343) is on positive values, so we should add one `layout.delta`
to distX or use `Math.ceil` function, or multiply offset.left by -1
before `Math.floor`
*/
distX = distX + this.layout.delta
distX = distX - width
}
this.scrollTo(distX, distY, true);
}
Expand Down Expand Up @@ -486,6 +505,8 @@ class DefaultViewManager {

if(next) {
this.clear();
// The new section may have a different writing-mode from the old section. Thus, we need to update layout.
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 @@ -577,6 +598,8 @@ class DefaultViewManager {

if(prev) {
this.clear();
// The new section may have a different writing-mode from the old section. Thus, we need to update layout.
this.updateLayout();

let forceRight = false;
if (this.layout.name === "pre-paginated" && this.layout.divisor === 2 && typeof prev.prev() !== "object") {
Expand Down Expand Up @@ -634,6 +657,7 @@ class DefaultViewManager {
}

currentLocation(){
this.updateLayout();
if (this.isPaginated && this.settings.axis === "horizontal") {
this.location = this.paginatedLocation();
} else {
Expand Down
14 changes: 13 additions & 1 deletion src/managers/views/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class IframeView {
layout: undefined,
globalLayoutProperties: {},
method: undefined,
forceRight: false
forceRight: false,
allowScriptedContent: false
}, options || {});

this.id = "epubjs-view-" + uuid();
Expand Down Expand Up @@ -88,6 +89,12 @@ class IframeView {
// Back up if seamless isn't supported
this.iframe.style.border = "none";

// sandbox
this.iframe.sandbox = "allow-same-origin";
if (this.settings.allowScriptedContent && this.section.properties.indexOf("scripted") > -1) {
this.iframe.sandbox += " allow-scripts"
}

this.iframe.setAttribute("enable-annotation", "true");

this.resizing = true;
Expand Down Expand Up @@ -816,6 +823,11 @@ class IframeView {
this.stopExpanding = true;
this.element.removeChild(this.iframe);

if (this.pane) {
this.pane.element.remove();
this.pane = undefined;
}

this.iframe = undefined;
this.contents = undefined;

Expand Down
67 changes: 30 additions & 37 deletions src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,38 @@ class Navigation {
*/
parseNav(navHtml){
var navElement = querySelectorByType(navHtml, "nav", "toc");
var navItems = navElement ? qsa(navElement, "li") : [];
var length = navItems.length;
var i;
var toc = {};
var list = [];
var item, parent;

if(!navItems || length === 0) return list;
if (!navElement) return list;

let navList = filterChildren(navElement, "ol", true);
if (!navList) return list;

list = this.parseNavList(navList);
return list;
}

/**
* Parses lists in the toc
* @param {document} navListHtml
* @param {string} parent id
* @return {array} navigation list
*/
parseNavList(navListHtml, parent) {
const result = [];

if (!navListHtml) return result;
if (!navListHtml.children) return result;

for (let i = 0; i < navListHtml.children.length; i++) {
const item = this.navItem(navListHtml.children[i], parent);

for (i = 0; i < length; ++i) {
item = this.navItem(navItems[i]);
if (item) {
toc[item.id] = item;
if(!item.parent) {
list.push(item);
} else {
parent = toc[item.parent];
parent.subitems.push(item);
}
result.push(item);
}
}

return list;
return result;
}

/**
Expand All @@ -180,7 +189,7 @@ class Navigation {
* @param {element} item
* @return {object} navItem
*/
navItem(item){
navItem(item, parent) {
let id = item.getAttribute("id") || undefined;
let content = filterChildren(item, "a", true);

Expand All @@ -194,27 +203,11 @@ class Navigation {
id = src;
}
let text = content.textContent || "";
let subitems = [];
let parentItem = getParentByTagName(item, "li");
let parent;

if (parentItem) {
parent = parentItem.getAttribute("id");
if (!parent) {
const parentContent = filterChildren(parentItem, "a", true);
parent = parentContent && parentContent.getAttribute("href");
}
}

while (!parent && parentItem) {
parentItem = getParentByTagName(parentItem, "li");
if (parentItem) {
parent = parentItem.getAttribute("id");
if (!parent) {
const parentContent = filterChildren(parentItem, "a", true);
parent = parentContent && parentContent.getAttribute("href");
}
}
let subitems = [];
let nested = filterChildren(item, "ol", true);
if (nested) {
subitems = this.parseNavList(nested, id);
}

return {
Expand Down
9 changes: 6 additions & 3 deletions src/rendition.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import ContinuousViewManager from "./managers/continuous/index";
* @param {boolean} [options.resizeOnOrientationChange] false to disable orientation events
* @param {string} [options.script] url of script to be injected
* @param {boolean | object} [options.snap=false] use snap scrolling
* @param {string} [options.defaultDirection='ltr'] default text direction
* @param {boolean} [options.allowScriptedContent=false] enable running scripts in content
*/
class Rendition {
constructor(book, options) {
Expand All @@ -54,7 +56,8 @@ class Rendition {
resizeOnOrientationChange: true,
script: null,
snap: false,
defaultDirection: "ltr"
defaultDirection: "ltr",
allowScriptedContent: false
});

extend(this.settings, options);
Expand Down Expand Up @@ -888,13 +891,13 @@ class Rendition {
/**
* Emit a selection event's CFI Range passed from a a view
* @private
* @param {EpubCFI} cfirange
* @param {string} cfirange
*/
triggerSelectedEvent(cfirange, contents){
/**
* Emit that a text selection has occured
* @event selected
* @param {EpubCFI} cfirange
* @param {string} cfirange
* @param {Contents} contents
* @memberof Rendition
*/
Expand Down
2 changes: 1 addition & 1 deletion src/resources.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {substitute} from "./utils/replacements";
import {createBase64Url, createBlobUrl, blob2base64} from "./utils/core";
import Url from "./utils/url";
import mime from "../libs/mime/mime";
import mime from "./utils/mime";
import Path from "./utils/path";
import path from "path-webpack";

Expand Down
2 changes: 1 addition & 1 deletion src/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Hook from "./utils/hook";
import { sprint } from "./utils/core";
import { replaceBase } from "./utils/replacements";
import Request from "./utils/request";
import { XMLDOMParser as XMLDOMSerializer } from "xmldom";
import { DOMParser as XMLDOMSerializer } from "xmldom";

/**
* Represents a Section of the Book
Expand Down
2 changes: 1 addition & 1 deletion src/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {defer, isXml, parse} from "./utils/core";
import httpRequest from "./utils/request";
import mime from "../libs/mime/mime";
import mime from "./utils/mime";
import Path from "./utils/path";
import EventEmitter from "event-emitter";
import localforage from "localforage";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const EPUBJS_VERSION = "0.3";

// Dom events to listen for
export const DOM_EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart", "touchmove"];
export const DOM_EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "mousemove", "click", "touchend", "touchstart", "touchmove"];

export const EVENTS = {
BOOK : {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ class Hook {
var promises = [];

this.hooks.forEach(function(task) {
var executing = task.apply(context, args);
try {
var executing = task.apply(context, args);
} catch (err) {
console.log(err);
}

if(executing && typeof executing["then"] === "function") {
// Task is a function that returns a promise
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion types/book.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class Book {

determineType(input: string): string;

getRange(cfiRange: string): Range;
getRange(cfiRange: string): Promise<Range>;

key(identifier?: string): string;

Expand Down
2 changes: 1 addition & 1 deletion types/epub.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import Book, { BookOptions } from "./book";

export default Epub;

declare function Epub(url: string, options?: BookOptions) : Book;
declare function Epub(urlOrData: string | ArrayBuffer, options?: BookOptions) : Book;
declare function Epub(options?: BookOptions) : Book;
3 changes: 2 additions & 1 deletion types/managers/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface ViewSettings {
method?: string,
width?: number,
height?: number,
forceEvenPages?: boolean
forceEvenPages?: boolean,
allowScriptedContent?: boolean
}

export default class View {
Expand Down
1 change: 1 addition & 0 deletions types/rendition.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface RenditionOptions {
overflow?: string,
snap?: boolean | object,
defaultDirection?: string,
allowScriptedContent?: boolean
}

export interface DisplayedLocation {
Expand Down