From 03aef890378d815c8c19dca849f4f8aa2b29b407 Mon Sep 17 00:00:00 2001 From: fchasen Date: Mon, 10 Nov 2014 09:16:32 -0500 Subject: [PATCH] New continuos render --- dist/epub.js | 1067 +++++++++++++++++++-- dist/epub.min.js | 4 +- examples/basic.html | 12 +- lib/epubjs/book.js | 2 +- lib/epubjs/continuous.js | 223 +++++ lib/epubjs/core.js | 70 ++ lib/epubjs/{pagination.js => paginate.js} | 0 lib/epubjs/renderer.js | 3 +- lib/epubjs/rendition.js | 544 +++++++++++ lib/epubjs/section.js | 4 +- lib/epubjs/spine.js | 12 +- lib/epubjs/view.js | 120 ++- lib/epubjs/viewmanager.js | 86 ++ 13 files changed, 2027 insertions(+), 120 deletions(-) create mode 100644 lib/epubjs/continuous.js rename lib/epubjs/{pagination.js => paginate.js} (100%) create mode 100644 lib/epubjs/rendition.js create mode 100644 lib/epubjs/viewmanager.js diff --git a/dist/epub.js b/dist/epub.js index 986ae9b..39bb5c6 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -1806,7 +1806,7 @@ EPUBJS.Book.prototype.section = function(target) { // Sugar to render a book EPUBJS.Book.prototype.renderTo = function(element, options) { - this.rendition = new EPUBJS.Renderer(this, options); + this.rendition = new EPUBJS.Rendition(this, options); this.rendition.attachTo(element); return this.rendition; }; @@ -1843,6 +1843,230 @@ RSVP.configure('instrument', true); //-- true | will logging out all RSVP reject RSVP.on('rejected', function(event){ console.error(event.detail.message, event.detail.stack); }); +EPUBJS.Continuous = function(book, _options){ + this.views = []; + this.container = container; + this.limit = limit || 4 + + // EPUBJS.Renderer.call(this, book, _options); +}; + +// EPUBJS.Continuous.prototype = Object.create(EPUBJS.Renderer.prototype); +// One rule -- every displayed view must have a next and prev + +EPUBJS.Continuous.prototype.append = function(view){ + this.views.push(view); + // view.appendTo(this.container); + this.container.appendChild(view.element()); + + view.onDisplayed = function(){ + var index = this.views.indexOf(view); + var next = view.section.next(); + var view; + + if(index + 1 === this.views.length && next) { + view = new EPUBJS.View(next); + this.append(view); + } + }.bind(this); + + this.resizeView(view); + + // If over the limit, destory first view +}; + +EPUBJS.Continuous.prototype.prepend = function(view){ + this.views.unshift(view); + // view.prependTo(this.container); + this.container.insertBefore(view.element, this.container.firstChild); + + view.onDisplayed = function(){ + var index = this.views.indexOf(view); + var prev = view.section.prev(); + var view; + + if(prev) { + view = new EPUBJS.View(prev); + this.append(view); + } + + }.bind(this); + + this.resizeView(view); + + // If over the limit, destory last view + +}; + +EPUBJS.Continuous.prototype.fill = function(view){ + + if(this.views.length){ + this.clear(); + } + + this.views.push(view); + + this.container.appendChild(view.element); + + view.onDisplayed = function(){ + var next = view.section.next(); + var prev = view.section.prev(); + var index = this.views.indexOf(view); + + var prevView, nextView; + + if(index + 1 === this.views.length && next) { + prevView = new EPUBJS.View(next); + this.append(prevView); + } + + if(index === 0 && prev) { + nextView = new EPUBJS.View(prev); + this.append(nextView); + } + + this.resizeView(view); + + }.bind(this); + +}; + +EPUBJS.Continuous.prototype.insert = function(view, index) { + this.views.splice(index, 0, view); + + if(index < this.cotainer.children.length){ + this.container.insertBefore(view.element(), this.container.children[index]); + } else { + this.container.appendChild(view.element()); + } + +}; + +// Remove the render element and clean up listeners +EPUBJS.Continuous.prototype.remove = function(view) { + var index = this.views.indexOf(view); + view.destroy(); + if(index > -1) { + this.views.splice(index, 1); + } +}; + +EPUBJS.Continuous.prototype.clear = function(){ + this.views.forEach(function(view){ + view.destroy(); + }); + + this.views = []; +}; + +EPUBJS.Continuous.prototype.first = function() { + return this.views[0]; +}; + +EPUBJS.Continuous.prototype.last = function() { + return this.views[this.views.length-1]; +}; + +EPUBJS.Continuous.prototype.each = function(func) { + return this.views.forEach(func); +}; + + +/* +EPUBJS.Continuous.prototype.add = function(section) { + var view; + + if(this.sections.length === 0) { + // Make a new view + view = new EPUBJS.View(section); + // Start filling + this.fill(view); + else if(section.index === this.last().index + 1) { + // Add To Bottom / Back + view = this.first(); + + // this.append(view); + } else if(section.index === this.first().index - 1){ + // Add to Top / Front + view = this.last() + // this.prepend(view); + } else { + this.clear(); + this.fill(view); + } + +}; +*/ + +EPUBJS.Continuous.prototype.check = function(){ + var container = this.container.getBoundingClientRect(); + var isVisible = function(view){ + var bounds = view.bounds(); + if((bounds.bottom >= container.top) && + !(bounds.top > container.bottom) && + (bounds.right >= container.left) && + !(bounds.left > container.right)) { + // Visible + console.log("visible", view.index); + + // Fit to size of the container, apply padding + this.resizeView(view); + + this.display(view); + } else { + console.log("off screen", view.index); + view.destroy(); + } + + }.bind(this); + this.views.forEach(this.isVisible); +}; + +EPUBJS.Continuous.prototype.displayView = function(view) { + // Render Chain + return view.display(this.book.request) + .then(function(){ + return this.hooks.display.trigger(view); + }.bind(this)) + .then(function(){ + return this.hooks.replacements.trigger(view, this); + }.bind(this)) + .then(function(){ + return view.expand(); + }.bind(this)) + .then(function(){ + this.rendering = false; + view.show(); + this.trigger("rendered", section); + return view; + }.bind(this)) + .catch(function(e){ + this.trigger("loaderror", e); + }.bind(this)); +}; + +EPUBJS.Continuous.prototype.resizeView = function(view) { + var bounds = this.container.getBoundingClientRect(); + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + right: parseFloat(styles["padding-right"]) || 0, + top: parseFloat(styles["padding-top"]) || 0, + bottom: parseFloat(styles["padding-bottom"]) || 0 + }; + var width = bounds.width - padding.left - padding.right; + var height = bounds.height - padding.top - padding.bottom; + var minHeight = 100; + var minWidth = 200; + + if(this.settings.axis === "vertical") { + view.resize(width, minHeight); + } else { + view.resize(minWidth, height); + } + +}; + EPUBJS.core = {}; EPUBJS.core.request = function(url, type, withCredentials, headers) { @@ -2199,6 +2423,76 @@ EPUBJS.core.defaults = function(obj) { return obj; }; +// Fast quicksort insert for sorted array -- based on: +// http://stackoverflow.com/questions/1344500/efficient-way-to-insert-a-number-into-a-sorted-array-of-numbers +EPUBJS.core.insert = function(item, array, compareFunction) { + var location = EPUBJS.core.locationOf(item, array, compareFunction); + array.splice(location, 0, item); + + return location; +}; +// Returns where something would fit in +EPUBJS.core.locationOf = function(item, array, compareFunction, _start, _end) { + var start = _start || 0; + var end = _end || array.length; + var pivot = parseInt(start + (end - start) / 2); + var compared; + if(!compareFunction){ + compareFunction = function(a, b) { + if(a > b) return 1; + if(a < b) return -1; + if(a = b) return 0; + }; + } + if(end-start <= 0) { + return pivot; + } + + compared = compareFunction(array[pivot], item); + if(end-start === 1) { + return compared > 0 ? pivot : pivot + 1; + } + + if(compared === 0) { + return pivot; + } + if(compared === -1) { + return EPUBJS.core.locationOf(item, array, compareFunction, pivot, end); + } else{ + return EPUBJS.core.locationOf(item, array, compareFunction, start, pivot); + } +}; +// Returns -1 of mpt found +EPUBJS.core.indexOfSorted = function(item, array, compareFunction, _start, _end) { + var start = _start || 0; + var end = _end || array.length; + var pivot = parseInt(start + (end - start) / 2); + var compared; + if(!compareFunction){ + compareFunction = function(a, b) { + if(a > b) return 1; + if(a < b) return -1; + if(a = b) return 0; + }; + } + if(end-start <= 0) { + return -1; // Not found + } + + compared = compareFunction(array[pivot], item); + if(end-start === 1) { + return compared === 0 ? pivot : -1; + } + if(compared === 0) { + return pivot; // Found + } + if(compared === -1) { + return EPUBJS.core.indexOfSorted(item, array, compareFunction, pivot, end); + } else{ + return EPUBJS.core.indexOfSorted(item, array, compareFunction, start, pivot); + } +}; + EPUBJS.EpubCFI = function(cfiStr){ if(cfiStr) return this.parse(cfiStr); }; @@ -3771,7 +4065,8 @@ EPUBJS.Renderer = function(book, _options) { width: typeof(options.width) === "undefined" ? false : options.width, height: typeof(options.height) === "undefined" ? false : options.height, overflow: typeof(options.overflow) === "undefined" ? "auto" : options.overflow, - padding: options.padding || "" + padding: options.padding || "", + offset: 400 }; this.book = book; @@ -4386,6 +4681,551 @@ EPUBJS.Renderer.prototype.bounds = function() { }; //-- Enable binding events to Renderer RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype); +EPUBJS.Rendition = function(book, options) { + this.settings = EPUBJS.core.defaults(options || {}, { + infinite: true, + hidden: false, + width: false, + height: false, + overflow: "auto", + axis: "vertical", + offset: 500 + }); + + this.book = book; + + this.container = this.initialize({ + "width" : this.settings.width, + "height" : this.settings.height + }); + + if(this.settings.hidden) { + this.wrapper = this.wrap(this.container); + } + + // this.views = new EPUBJS.ViewManager(this.container); + this.views = []; + + this.tick = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; + this.scrolled = false; + + // if(this.settings.infinite) { + // this.infinite = new EPUBJS.Infinite(this.container, this.settings.axis); + // this.infinite.on("scroll", this.checkCurrent.bind(this)); + // } + + //-- Adds Hook methods to the Renderer prototype + this.hooks = {}; + this.hooks.display = new EPUBJS.Hook(this); + this.hooks.replacements = new EPUBJS.Hook(this); + + // this.hooks.replacements.register(this.replacements.bind(this)); + // this.hooks.display.register(this.afterDisplay.bind(this)); + + this.container.addEventListener("scroll", function(e){ + if(!this.ignore) { + this.scrolled = true; + } else { + this.ignore = false; + } + }.bind(this)); + +}; + +EPUBJS.Rendition.prototype.handleScroll = function(){ + + if(this.scrolled && !this.displaying) { + + this.check(); + + this.scrolled = false; + } else { + this.displaying = false; + this.scrolled = false; + } + + this.tick.call(window, this.handleScroll.bind(this)); + // setTimeout(this.check.bind(this), 100); +}; + +/** +* Creates an element to render to. +* Resizes to passed width and height or to the elements size +*/ +EPUBJS.Rendition.prototype.initialize = function(_options){ + var options = _options || {}; + var height = options.height !== false ? options.height : "100%"; + var width = options.width !== false ? options.width : "100%"; + var hidden = options.hidden || false; + var container; + var wrapper; + + if(options.height && EPUBJS.core.isNumber(options.height)) { + height = options.height + "px"; + } + + if(options.width && EPUBJS.core.isNumber(options.width)) { + width = options.width + "px"; + } + + // Create new container element + container = document.createElement("div"); + + // Style Element + if(this.settings.axis === "horizontal") { + // this.container.style.display = "flex"; + // this.container.style.flexWrap = "nowrap"; + container.style.whiteSpace = "nowrap"; + } + + container.style.width = width; + container.style.height = height; + container.style.overflow = this.settings.overflow; + + return container; +}; + +EPUBJS.Rendition.wrap = function(container) { + var wrapper = document.createElement("div"); + + wrapper.style.visibility = "hidden"; + wrapper.style.overflow = "hidden"; + wrapper.style.width = "0"; + wrapper.style.height = "0"; + + wrapper.appendChild(container); + return wrapper; +}; + +// Call to attach the container to an element in the dom +// Container must be attached before rendering can begin +EPUBJS.Rendition.prototype.attachTo = function(_element){ + var bounds; + + if(EPUBJS.core.isElement(_element)) { + this.element = _element; + } else if (typeof _element === "string") { + this.element = document.getElementById(_element); + } + + if(!this.element){ + console.error("Not an Element"); + return; + } + + // If width or height are not set, inherit them from containing element + if(this.settings.height === false) { + bounds = this.element.getBoundingClientRect(); + this.container.style.height = bounds.height + "px"; + } + + if(this.settings.width === false) { + bounds = bounds || this.element.getBoundingClientRect(); + this.container.style.width = bounds.width + "px"; + } + + this.element.appendChild(this.container); + + // Attach Listeners + this.attachListeners(); + + // Trigger Attached + +}; + +EPUBJS.Rendition.prototype.attachListeners = function(){ + + // Listen to window for resize event + window.addEventListener("resize", this.onResized.bind(this), false); + + +}; + +EPUBJS.Rendition.prototype.bounds = function() { + return this.container.getBoundingClientRect(); +}; + +EPUBJS.Rendition.prototype.display = function(what){ + var displaying = new RSVP.defer(); + var displayed = displaying.promise; + + + // Check for fragments + if(typeof what === 'string') { + what = what.split("#")[0]; + } + + this.book.opened.then(function(){ + var section = this.book.spine.get(what); + var view; + + this.displaying = true; + + if(section){ + view = new EPUBJS.View(section); + // Clear views + // this.clear(); + this.fill(view); + // rendered = this.render(section); + + // if(this.settings.infinite) { + // rendered.then(function(){ + // return this.fill.call(this); + // }.bind(this)); + // } + this.check(); + this.handleScroll(); + + view.displayed.then(function(){ + this.trigger("displayed", section); + this.displaying = false; + displaying.resolve(this); + }.bind(this)); + + } else { + displaying.reject(new Error("No Section Found")); + } + + }.bind(this)); + + return displayed; +}; + +EPUBJS.Rendition.prototype.render = function(view) { + // var view = new EPUBJS.View(section); + // + // if(!section) { + // rendered = new RSVP.defer(); + // rendered.reject(new Error("No Section Provided")); + // return rendered.promise; + // } + view.create(); + + // Fit to size of the container, apply padding + this.resizeView(view); + + // Render Chain + return view.display(this.book.request) + .then(function(){ + return this.hooks.display.trigger(view); + }.bind(this)) + .then(function(){ + return this.hooks.replacements.trigger(view, this); + }.bind(this)) + .then(function(){ + return view.expand(); + }.bind(this)) + .then(function(){ + this.rendering = false; + view.show(); + this.trigger("rendered", view.section); + this.check(); // Check to see if anything new is on screen after rendering + return view; + }.bind(this)) + .catch(function(e){ + this.trigger("loaderror", e); + }.bind(this)); + +}; + +EPUBJS.Rendition.prototype.afterDisplayed = function(currView){ + var next = currView.section.next(); + var prev = currView.section.prev(); + var index = this.views.indexOf(currView); + + var prevView, nextView; + + if(index + 1 === this.views.length && next) { + nextView = new EPUBJS.View(next); + this.append(nextView); + } + + if(index === 0 && prev) { + prevView = new EPUBJS.View(prev); + this.prepend(prevView); + } + + this.resizeView(currView); + +}; + +EPUBJS.Rendition.prototype.append = function(view){ + this.views.push(view); + // view.appendTo(this.container); + this.container.appendChild(view.element); + + view.onDisplayed = this.afterDisplayed.bind(this); + + this.resizeView(view); +}; + +EPUBJS.Rendition.prototype.prepend = function(view){ + this.views.unshift(view); + // view.prependTo(this.container); + this.container.insertBefore(view.element, this.container.firstChild); + + var prevTop = this.container.scrollTop; + var prevLeft = this.container.scrollLeft; + + view.onDisplayed = function(){ + + var bounds = view.bounds(); + var style = window.getComputedStyle(view.element); + var marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0; + var marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0; + + if(this.settings.axis === "vertical") { + this.scrollTo(0, prevTop - bounds.height - marginTopBottom, true); + } else { + this.scrollTo(prevLeft - bounds.width - marginLeftRight, 0, true); + } + + this.afterDisplayed.bind(this); + }.bind(this); + this.resizeView(view); +}; + +EPUBJS.Rendition.prototype.fill = function(view){ + + if(this.views.length){ + this.clear(); + } + + this.views.push(view); + + this.container.appendChild(view.element); + + view.onDisplayed = this.afterDisplayed.bind(this); + +}; + +EPUBJS.Rendition.prototype.insert = function(view, index) { + this.views.splice(index, 0, view); + + if(index < this.cotainer.children.length){ + this.container.insertBefore(view.element, this.container.children[index]); + } else { + this.container.appendChild(view.element); + } + +}; + +// Remove the render element and clean up listeners +EPUBJS.Rendition.prototype.remove = function(view) { + var index = this.views.indexOf(view); + if(index > -1) { + this.views.splice(index, 1); + } + + this.container.removeChild(view.element); + + if(view.shown){ + view.destroy(); + } + + view = null; + +}; + +EPUBJS.Rendition.prototype.clear = function(){ + this.views.forEach(function(view){ + view.destroy(); + }); + + this.views = []; +}; + +EPUBJS.Rendition.prototype.first = function() { + return this.views[0]; +}; + +EPUBJS.Rendition.prototype.last = function() { + return this.views[this.views.length-1]; +}; + +EPUBJS.Rendition.prototype.each = function(func) { + return this.views.forEach(func); +}; + + +EPUBJS.Rendition.prototype.check = function(){ + var container = this.container.getBoundingClientRect(); + var isVisible = function(view){ + var bounds = view.bounds(); + if((bounds.bottom >= container.top - this.settings.offset) && + !(bounds.top > container.bottom) && + (bounds.right >= container.left) && + !(bounds.left > container.right)) { + // Visible + + // Fit to size of the container, apply padding + // this.resizeView(view); + if(!view.shown) { + console.log("visible", view.index); + this.render(view); + } + + } else { + + if(view.shown) { + console.log("off screen", view.index); + + + view.destroy(); + + } + } + + }.bind(this); + + this.views.forEach(function(view){ + isVisible(view); + }); + + clearTimeout(this.trimTimeout); + this.trimTimeout = setTimeout(function(){ + this.trim(); + }.bind(this), 250); +}; + +EPUBJS.Rendition.prototype.trim = function(){ + + for (var i = 0; i < this.views.length; i++) { + var view = this.views[i]; + var prevShown = i > 0 ? this.views[i-1].shown : false; + var nextShown = (i+1 < this.views.length) ? this.views[i+1].shown : false; + if(!view.shown && !prevShown && !nextShown) { + // Remove + this.erase(view); + } + } +}; + +EPUBJS.Rendition.prototype.erase = function(view){ //Trim + + // remove from dom + var prevTop = this.container.scrollTop; + var prevLeft = this.container.scrollLeft; + var bounds = view.bounds(); + var style = window.getComputedStyle(view.element); + var marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0; + var marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0; + + this.remove(view); + + if(this.settings.axis === "vertical") { + this.scrollTo(0, prevTop - bounds.height - marginTopBottom, true); + } else { + this.scrollTo(prevLeft - bounds.width - marginLeftRight, 0, true); + } + +}; + +EPUBJS.Rendition.prototype.scrollBy = function(x, y, silent){ + if(silent) { + this.displaying = true; + } + this.container.scrollLeft += x; + this.container.scrollTop += y; + + this.scrolled = true; + this.check(); +}; + +EPUBJS.Rendition.prototype.scrollTo = function(x, y, silent){ + if(silent) { + this.displaying = true; + } + this.container.scrollLeft = x; + this.container.scrollTop = y; + + this.scrolled = true; + console.log("scrolled:", y) + // if(this.container.scrollLeft != x){ + // setTimeout(function() { + // this.scrollTo(x, y, silent); + // }.bind(this), 10); + // return; + // }; + + this.check(); + +}; + + +EPUBJS.Rendition.prototype.resizeView = function(view) { + var bounds = this.container.getBoundingClientRect(); + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + right: parseFloat(styles["padding-right"]) || 0, + top: parseFloat(styles["padding-top"]) || 0, + bottom: parseFloat(styles["padding-bottom"]) || 0 + }; + var width = bounds.width - padding.left - padding.right; + var height = bounds.height - padding.top - padding.bottom; + var minHeight = 100; + var minWidth = 200; + + if(this.settings.axis === "vertical") { + view.resize(width, 0); + } else { + view.resize(0, height); + } + +}; + +EPUBJS.Rendition.prototype.resize = function(_width, _height){ + var width = _width; + var height = _height; + + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + right: parseFloat(styles["padding-right"]) || 0, + top: parseFloat(styles["padding-top"]) || 0, + bottom: parseFloat(styles["padding-bottom"]) || 0 + }; + + var stagewidth = width - padding.left - padding.right; + var stageheight = height - padding.top - padding.bottom; + + if(!_width) { + width = window.innerWidth; + } + if(!_height) { + height = window.innerHeight; + } + + // this.container.style.width = width + "px"; + // this.container.style.height = height + "px"; + + this.trigger("resized", { + width: this.width, + height: this.height + }); + + + this.views.forEach(function(view){ + if(this.settings.axis === "vertical") { + view.resize(stagewidth, 0); + } else { + view.resize(0, stageheight); + } + }.bind(this)); + +}; + +EPUBJS.Rendition.prototype.onResized = function(e) { + var bounds = this.element.getBoundingClientRect(); + + + this.resize(bounds.width, bounds.height); +}; + +//-- Enable binding events to Renderer +RSVP.EventTarget.mixin(EPUBJS.Rendition.prototype); + EPUBJS.Section = function(item){ this.idref = item.idref; this.linear = item.linear; @@ -4394,7 +5234,9 @@ EPUBJS.Section = function(item){ this.href = item.href; this.url = item.url; this.cfiBase = item.cfiBase; - + this.next = item.next; + this.prev = item.prev; + this.hooks = {}; this.hooks.replacements = new EPUBJS.Hook(this); @@ -4502,7 +5344,15 @@ EPUBJS.Spine.prototype.load = function(_package) { item.href = manifestItem.href; item.url = this.baseUrl + item.href; } - + + // if(index > 0) { + item.prev = function(){ return this.get(index-1); }.bind(this); + // } + + // if(index+1 < this.items.length) { + item.next = function(){ return this.get(index+1); }.bind(this); + // } + spineItem = new EPUBJS.Section(item); this.append(spineItem); @@ -4526,7 +5376,7 @@ EPUBJS.Spine.prototype.get = function(target) { index = this.spineByHref[target]; } - return this.spineItems[index]; + return this.spineItems[index] || null; }; EPUBJS.Spine.prototype.append = function(section) { @@ -4570,13 +5420,21 @@ EPUBJS.Spine.prototype.remove = function(section) { }; EPUBJS.View = function(section) { this.id = "epubjs-view:" + EPUBJS.core.uuid(); - this.rendering = new RSVP.defer(); - this.rendered = this.rendering.promise; - // this.iframe = this.create(); + this.displaying = new RSVP.defer(); + this.displayed = this.displaying.promise; this.section = section; + this.index = section.index; + + this.element = document.createElement('div'); + this.element.classList.add("epub-view"); + this.element.style.display = "inline-block"; + this.element.minHeight = "100px"; + + this.shown = false; }; EPUBJS.View.prototype.create = function(width, height) { + this.iframe = document.createElement('iframe'); this.iframe.id = this.id; this.iframe.scrolling = "no"; @@ -4586,32 +5444,38 @@ EPUBJS.View.prototype.create = function(width, height) { this.resizing = true; - if(width){ - this.iframe.style.width = width + "px"; - } - - if(height){ - this.iframe.style.height = height + "px"; + if(width || height){ + this.resize(width, height); } this.iframe.style.display = "none"; this.iframe.style.visibility = "hidden"; + + this.element.appendChild(this.iframe); return this.iframe; }; EPUBJS.View.prototype.resize = function(width, height) { if(width){ - this.iframe.style.width = width + "px"; + if(this.iframe) { + this.iframe.style.width = width + "px"; + } + this.element.style.minWidth = width + "px"; } if(height){ - this.iframe.style.height = height + "px"; + if(this.iframe) { + this.iframe.style.height = height + "px"; + } + this.element.style.minHeight = height + "px"; } if (!this.resizing) { this.resizing = true; - this.expand(); + if(this.iframe) { + this.expand(); + } } }; @@ -4619,7 +5483,6 @@ EPUBJS.View.prototype.resize = function(width, height) { EPUBJS.View.prototype.resized = function(e) { if (!this.resizing) { - console.log("resize"); this.expand(); } else { this.resizing = false; @@ -4627,15 +5490,18 @@ EPUBJS.View.prototype.resized = function(e) { }; -EPUBJS.View.prototype.render = function(_request) { +EPUBJS.View.prototype.display = function(_request) { + this.shown = true; + return this.section.render(_request) .then(function(contents){ return this.load(contents); }.bind(this)) - .then(this.display.bind(this)) + .then(this.afterLoad.bind(this)) + .then(this.displaying.resolve.call()) .then(function(){ - this.rendering.resolve(this); - }.bind(this)); + this.onDisplayed(this); + }.bind(this)); // TEMP... TODO: proper callback }; EPUBJS.View.prototype.load = function(contents) { @@ -4667,10 +5533,9 @@ EPUBJS.View.prototype.load = function(contents) { return loaded; }; -EPUBJS.View.prototype.display = function(contents) { - var displaying = new RSVP.defer(); - var displayed = displaying.promise; - + +EPUBJS.View.prototype.afterLoad = function() { + // this.iframe.style.display = "block"; this.iframe.style.display = "inline-block"; @@ -4679,27 +5544,22 @@ EPUBJS.View.prototype.display = function(contents) { this.document.body.style.margin = "0"; this.document.body.style.display = "inline-block"; this.document.documentElement.style.width = "auto"; - + setTimeout(function(){ this.window.addEventListener("resize", this.resized.bind(this), false); }.bind(this), 10); // Wait to listen for resize events + // Wait for fonts to load to finish + if(this.document.fonts.status === "loading") { + this.document.fonts.onloading = function(){ + this.expand(); + }.bind(this); + } - // if(!this.document.fonts || this.document.fonts.status !== "loading") { - // this.expand(); - // displaying.resolve(this); - // } else { - // this.document.fonts.onloading = function(){ - // this.expand(); - // displaying.resolve(this); - // }.bind(this); - // } - - displaying.resolve(this); - // this.observer = this.observe(this.document.body); - - return displayed; + if(this.observe) { + this.observer = this.observe(this.document.body); + } }; @@ -4708,9 +5568,11 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { var width, height; var expanding = _defer || new RSVP.defer(); var expanded = expanding.promise; + var fontsLoading = false; // Stop checking for equal height after 10 tries var MAX = 10; + var TIMEOUT = 10; var count = _count || 0; // Flag Changes @@ -4730,7 +5592,7 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { setTimeout(function(){ this.expand(expanding, count); - }.bind(this), 10); + }.bind(this), TIMEOUT); } else { expanding.resolve(); @@ -4739,9 +5601,10 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { this.width = width; this.height = height; - this.iframe.style.height = height + "px"; - this.iframe.style.width = width + "px"; - + // this.iframe.style.height = height + "px"; + // this.iframe.style.width = width + "px"; + this.resize(width, height); + return expanded; }; @@ -4765,15 +5628,15 @@ EPUBJS.View.prototype.observe = function(target) { return observer; }; -EPUBJS.View.prototype.appendTo = function(element) { - this.element = element; - this.element.appendChild(this.iframe); -}; - -EPUBJS.View.prototype.prependTo = function(element) { - this.element = element; - element.insertBefore(this.iframe, element.firstChild); -}; +// EPUBJS.View.prototype.appendTo = function(element) { +// this.element = element; +// this.element.appendChild(this.iframe); +// }; +// +// EPUBJS.View.prototype.prependTo = function(element) { +// this.element = element; +// element.insertBefore(this.iframe, element.firstChild); +// }; EPUBJS.View.prototype.show = function() { // this.iframe.style.display = "block"; @@ -4787,13 +5650,103 @@ EPUBJS.View.prototype.hide = function() { }; EPUBJS.View.prototype.bounds = function() { - return this.iframe.getBoundingClientRect(); + return this.element.getBoundingClientRect(); }; EPUBJS.View.prototype.destroy = function() { // Stop observing // this.observer.disconnect(); - - this.element.removeChild(this.iframe); + if(this.iframe){ + this.element.removeChild(this.iframe); + this.shown = false; + this.iframe = null; + } +}; + + +// View Management +EPUBJS.ViewManager = function(container){ + this.views = []; + this.container = container; +}; + +EPUBJS.ViewManager.prototype.append = function(view){ + this.views.push(view); + // view.appendTo(this.container); + this.container.appendChild(view.element()); + +}; + +EPUBJS.ViewManager.prototype.prepend = function(view){ + this.views.unshift(view); + // view.prependTo(this.container); + this.container.insertBefore(view.element(), this.container.firstChild); +}; + +EPUBJS.ViewManager.prototype.insert = function(view, index) { + this.views.splice(index, 0, view); + + if(index < this.cotainer.children.length){ + this.container.insertBefore(view.element(), this.container.children[index]); + } else { + this.container.appendChild(view.element()); + } + +}; + +EPUBJS.Renderer.prototype.add = function(view) { + var section = view.section; + var index = -1; + + if(this.views.length === 0 || view.index > this.last().index) { + this.append(view); + index = this.views.length; + } else if(view.index < this.first().index){ + this.prepend(view); + index = 0; + } else { + // Sort the views base on index + index = EPUBJS.core.locationOf(view, this.views, function(){ + if (a.index > b.index) { + return 1; + } + if (a.index < b.index) { + return -1; + } + return 0; + }); + + // Place view in correct position + this.insert(view, index); + } +}; + +// Remove the render element and clean up listeners +EPUBJS.ViewManager.prototype.remove = function(view) { + var index = this.views.indexOf(view); + view.destroy(); + if(index > -1) { + this.views.splice(index, 1); + } +}; + +EPUBJS.ViewManager.prototype.clear = function(){ + this.views.forEach(function(view){ + view.destroy(); + }); + + this.views = []; +}; + +EPUBJS.ViewManager.prototype.first = function() { + return this.views[0]; +}; + +EPUBJS.ViewManager.prototype.last = function() { + return this.views[this.views.length-1]; +}; + +EPUBJS.ViewManager.prototype.map = function(func) { + return this.views.map(func); }; diff --git a/dist/epub.min.js b/dist/epub.min.js index ad5dc47..6cf387d 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,2 +1,2 @@ -"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(e){"use strict";var t=function(e){return new EPUBJS.Book(e)};t.Render={register:function(e,i){t.Render[e]=i}},"object"==typeof exports?(e.RSVP=require("rsvp"),module.exports=t):"function"==typeof define&&define.amd?define(t):e.ePub=t}(this),function(){"use strict";function e(e,t){for(var i=0,n=e.length;n>i;i++)if(e[i]===t)return i;return-1}function t(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}function i(e,t){return"onerror"===e?(Y.on("error",t),void 0):2!==arguments.length?Y[e]:(Y[e]=t,void 0)}function n(e){return"function"==typeof e||"object"==typeof e&&null!==e}function r(e){return"function"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(){}function a(){}function h(e){try{return e.then}catch(t){return ot.error=t,ot}}function c(e,t,i,n){try{e.call(t,i,n)}catch(r){return r}}function u(e,t,i){Y.async(function(e){var n=!1,r=c(i,t,function(i){n||(n=!0,t!==i?d(e,i):g(e,i))},function(t){n||(n=!0,y(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&r&&(n=!0,y(e,r))},e)}function p(e,t){t._state===nt?g(e,t._result):e._state===rt?y(e,t._result):m(t,void 0,function(i){t!==i?d(e,i):g(e,i)},function(t){y(e,t)})}function l(e,t){if(t.constructor===e.constructor)p(e,t);else{var i=h(t);i===ot?y(e,ot.error):void 0===i?g(e,t):r(i)?u(e,t,i):g(e,t)}}function d(e,t){e===t?g(e,t):n(t)?l(e,t):g(e,t)}function f(e){e._onerror&&e._onerror(e._result),v(e)}function g(e,t){e._state===it&&(e._result=t,e._state=nt,0===e._subscribers.length?Y.instrument&&tt("fulfilled",e):Y.async(v,e))}function y(e,t){e._state===it&&(e._state=rt,e._result=t,Y.async(f,e))}function m(e,t,i,n){var r=e._subscribers,o=r.length;e._onerror=null,r[o]=t,r[o+nt]=i,r[o+rt]=n,0===o&&e._state&&Y.async(v,e)}function v(e){var t=e._subscribers,i=e._state;if(Y.instrument&&tt(i===nt?"fulfilled":"rejected",e),0!==t.length){for(var n,r,o=e._result,s=0;sa;a++)s[a]=e[a];for(n=0;nn;n++)i[n-1]=e[n];return i}function N(e,t){return{then:function(i,n){return e.call(t,i,n)}}}function I(e,t,i,n){var r=k(i,n,t);return r===gt&&y(e,r.value),e}function F(e,t,i,n){return ft.all(t).then(function(t){var r=k(i,n,t);return r===gt&&y(e,r.value),e})}function A(e){return e&&"object"==typeof e?e.constructor===ft?!0:_(e):!1}function O(e,t,i){this._superConstructor(e,t,!1,i)}function V(e,t,i){this._superConstructor(e,t,!0,i)}function q(e,t,i){this._superConstructor(e,t,!1,i)}function L(){return function(){process.nextTick(z)}}function M(){var e=0,t=new It(z),i=document.createTextNode("");return t.observe(i,{characterData:!0}),function(){i.data=e=++e%2}}function j(){var e=new MessageChannel;return e.port1.onmessage=z,function(){e.port2.postMessage(0)}}function H(){return function(){setTimeout(z,1)}}function z(){for(var e=0;Ct>e;e+=2){var t=At[e],i=At[e+1];t(i),At[e]=void 0,At[e+1]=void 0}Ct=0}function W(e,t){Y.async(e,t)}function D(){Y.on.apply(Y,arguments)}function X(){Y.off.apply(Y,arguments)}var K={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(i,n){var r,o=t(this);r=o[i],r||(r=o[i]=[]),-1===e(r,n)&&r.push(n)},off:function(i,n){var r,o,s=t(this);return n?(r=s[i],o=e(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(e,i){var n,r,o=t(this);if(n=o[e])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof e)throw new TypeError("Argument must be an object");return s.prototype=e,new s},et=[],tt=function(e,t,i){1===et.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:i&&t._guidKey+i._id,label:t._label,timeStamp:Z(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;tn;n++)this._eachEntry(i[n],n)},B.prototype._eachEntry=function(e,t){var i=this._instanceConstructor;o(e)?e.constructor===i&&e._state!==it?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(i.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(nt,t,e))},B.prototype._settledAt=function(e,t,i){var n=this.promise;n._state===it&&(this._remaining--,this._abortOnReject&&e===rt?y(n,i):this._result[t]=this._makeResult(e,t,i)),0===this._remaining&&g(n,this._result)},B.prototype._makeResult=function(e,t,i){return i},B.prototype._willSettleAt=function(e,t){var i=this;m(e,void 0,function(e){i._settledAt(nt,t,e)},function(e){i._settledAt(rt,t,e)})};var ht=function(e,t){return new at(this,e,!0,t).promise},ct=function(e,t){function i(e){d(o,e)}function n(e){y(o,e)}var r=this,o=new r(a,t);if(!Q(e))return y(o,new TypeError("You must pass an array to race.")),o;for(var s=e.length,h=0;o._state===it&&s>h;h++)m(r.resolve(e[h]),void 0,i,n);return o},ut=function(e,t){var i=this;if(e&&"object"==typeof e&&e.constructor===i)return e;var n=new i(a,t);return d(n,e),n},pt=function(e,t){var i=this,n=new i(a,t);return y(n,e),n},lt="rsvp_"+Z()+"-",dt=0,ft=J;J.cast=ut,J.all=ht,J.race=ct,J.resolve=ut,J.reject=pt,J.prototype={constructor:J,_guidKey:lt,_onerror:function(e){Y.trigger("error",e)},then:function(e,t,i){var n=this,r=n._state;if(r===nt&&!e||r===rt&&!t)return Y.instrument&&tt("chained",this,this),this;n._onerror=null;var o=new this.constructor(a,i),s=n._result;if(Y.instrument&&tt("chained",n,o),r){var h=arguments[r-1];Y.async(function(){P(r,o,h,s)})}else m(n,o,e,t);return o},"catch":function(e,t){return this.then(null,e,t)},"finally":function(e,t){var i=this.constructor;return this.then(function(t){return i.resolve(e()).then(function(){return t})},function(t){return i.resolve(e()).then(function(){throw t})},t)}};var gt=new R,yt=new R,mt=function(e,t){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,h=0;r>h;++h){if(i=arguments[h],!s){if(s=A(i),s===yt){var c=new ft(a);return y(c,yt.value),c}s&&s!==!0&&(i=N(s,i))}o[h]=i}var u=new ft(a);return o[r]=function(e,i){e?y(u,e):void 0===t?d(u,i):t===!0?d(u,T(arguments)):Q(t)?d(u,C(arguments,t)):d(u,i)},s?F(u,o,e,n):I(u,o,e,n)};return i.__proto__=e,i},vt=function(e,t){return ft.all(e,t)};O.prototype=$(at.prototype),O.prototype._superConstructor=at,O.prototype._makeResult=b,O.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var St=function(e,t){return new O(ft,e,t).promise},Et=function(e,t){return ft.race(e,t)},Pt=V;V.prototype=$(at.prototype),V.prototype._superConstructor=at,V.prototype._init=function(){this._result={}},V.prototype._validateInput=function(e){return e&&"object"==typeof e},V.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},V.prototype._enumerate=function(){var e=this.promise,t=this._input,i=[];for(var n in t)e._state===it&&t.hasOwnProperty(n)&&i.push({position:n,entry:t[n]});var r=i.length;this._remaining=r;for(var o,s=0;e._state===it&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var wt=function(e,t){return new Pt(ft,e,t).promise};q.prototype=$(Pt.prototype),q.prototype._superConstructor=at,q.prototype._makeResult=b,q.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var bt,Bt=function(e,t){return new q(ft,e,t).promise},Ut=function(e){throw setTimeout(function(){throw e}),e},xt=function(e){var t={};return t.promise=new ft(function(e,i){t.resolve=e,t.reject=i},e),t},Jt=function(e,t,i){return ft.all(e,i).then(function(e){if(!r(t))throw new TypeError("You must pass a function as map's second argument.");for(var n=e.length,o=new Array(n),s=0;n>s;s++)o[s]=t(e[s]);return ft.all(o,i)})},Rt=function(e,t){return ft.resolve(e,t)},_t=function(e,t){return ft.reject(e,t)},kt=function(e,t,i){return ft.all(e,i).then(function(e){if(!r(t))throw new TypeError("You must pass a function as filter's second argument.");for(var n=e.length,o=new Array(n),s=0;n>s;s++)o[s]=t(e[s]);return ft.all(o,i).then(function(t){for(var i=new Array(n),r=0,o=0;n>o;o++)t[o]&&(i[r]=e[o],r++);return i.length=r,i})})},Ct=0,Tt=function(e,t){At[Ct]=e,At[Ct+1]=t,Ct+=2,2===Ct&&bt()},Nt="undefined"!=typeof window?window:{},It=Nt.MutationObserver||Nt.WebKitMutationObserver,Ft="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,At=new Array(1e3);bt="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?L():It?M():Ft?j():H(),Y.async=Tt;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Ot=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Vt in Ot)Ot.hasOwnProperty(Vt)&&D(Vt,Ot[Vt])}var qt={race:Et,Promise:ft,allSettled:St,hash:wt,hashSettled:Bt,denodeify:mt,on:D,off:X,map:Jt,filter:kt,resolve:Rt,reject:_t,all:vt,rethrow:Ut,defer:xt,EventTarget:K,configure:i,async:W};"function"==typeof define&&define.amd?define(function(){return qt}):"undefined"!=typeof module&&module.exports?module.exports=qt:"undefined"!=typeof this&&(this.RSVP=qt)}.call(this),EPUBJS.Book=function(e){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),e&&this.open(e)},EPUBJS.Book.prototype.open=function(e){var t,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return e?(t="object"==typeof e?e:EPUBJS.core.uri(e),"opf"===t.extension?(this.packageUrl=t.href,this.containerUrl="",t.origin?this.url=t.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,t.directory)):this.url=t.directory,i=this.request(this.packageUrl)):"epub"===t.extension||"zip"===t.extension?(this.archived=!0,this.url=""):t.extension||(this.containerUrl=e+s,i=this.request(this.containerUrl).then(function(e){return r.container(e)}).then(function(t){var i=EPUBJS.core.uri(t.packagePath);return o.packageUrl=e+t.packagePath,o.url=e+i.directory,o.encoding=t.encoding,o.request(o.packageUrl)}).catch(function(e){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(e)})),i.then(function(e){o.unpack(e),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(e){console.error(e.message,e.stack),o.opening.reject(e)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(e){var t=this,i=new EPUBJS.Parser;t.package=i.packageContents(e),t.package.baseUrl=t.url,this.spine.load(t.package),t.navigation=new EPUBJS.Navigation(t.package,this.request),t.navigation.load().then(function(e){t.toc=e,t.loading.navigation.resolve(t.toc)}),t.cover=t.url+t.package.coverPath},EPUBJS.Book.prototype.section=function(e){return this.spine.get(e)},EPUBJS.Book.prototype.renderTo=function(e,t){return this.rendition=new EPUBJS.Renderer(this,t),this.rendition.attachTo(e),this.rendition},EPUBJS.Book.prototype.requestMethod=function(e){return this.archived?void 0:EPUBJS.core.request(e,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(e){this.requestCredentials=e},EPUBJS.Book.prototype.setRequestHeaders=function(e){this.requestHeaders=e},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(e){console.error(e.detail.message,e.detail.stack)}),EPUBJS.core={},EPUBJS.core.request=function(e,t,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var e;e="xml"==t?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==t?JSON.parse(this.response):"blob"==t?s?this.response:new Blob([this.response]):this.response,h.resolve(e)}else h.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,a=s?"blob":"arraybuffer",h=new RSVP.defer,c=new XMLHttpRequest,u=XMLHttpRequest.prototype;"overrideMimeType"in u||Object.defineProperty(u,"overrideMimeType",{value:function(){}}),i&&(c.withCredentials=!0),c.open("GET",e,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==t&&(c.responseType=a),"json"==t&&c.setRequestHeader("Accept","application/json"),"xml"==t&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(e){var t,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:e},o=e.indexOf("://"),s=e.indexOf("?"),a=e.indexOf("#");return-1!=a&&(r.fragment=e.slice(a+1),e=e.slice(0,a)),-1!=s&&(r.search=e.slice(s+1),e=e.slice(0,s),href=e),-1!=o?(r.protocol=e.slice(0,o),t=e.slice(o+3),n=t.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=t.slice(0,n),r.path=t.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=e,r.directory=EPUBJS.core.folder(e),r.base=r.directory),r.filename=e.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(e){var t=e.lastIndexOf("/");if(-1==t)var i="";return i=e.slice(0,t+1)},EPUBJS.core.queue=function(e){var t=[],i=e,n=function(e,i,n){return t.push({funcName:e,args:i,context:n}),t},r=function(){var e;t.length&&(e=t.shift(),i[e.funcName].apply(e.context||i,e.args))},o=function(){for(;t.length;)r()},s=function(){t=[]},a=function(){return t.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(e){return!(!e||1!=e.nodeType)},EPUBJS.core.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:7&i|8).toString(16)});return t},EPUBJS.core.values=function(e){for(var t=-1,i=Object.keys(e),n=i.length,r=Array(n);++tr;r++)if("undefined"!=typeof document.body.style[t[r]+i])return t[r]+i;return e},EPUBJS.core.defaults=function(e){for(var t=1,i=arguments.length;i>t;t++){var n=arguments[t];for(var r in n)void 0===e[r]&&(e[r]=n[r])}return e},EPUBJS.EpubCFI=function(e){return e?this.parse(e):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(e,t,i){var n=parseInt(t),r=e+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(e){var t=[];return e.forEach(function(e){var i="";i+=2*(e.index+1),e.id&&(i+="["+e.id+"]"),t.push(i)}),t.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(e,t){var i=this.pathTo(e),n=this.generatePathComponent(i);return n.length?"epubcfi("+t+"!"+n+"/1:0)":"epubcfi("+t+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(e){for(var t,i=[];e&&null!==e.parentNode&&9!=e.parentNode.nodeType;)t=e.parentNode.children,i.unshift({id:e.id,tagName:e.tagName,index:t?Array.prototype.indexOf.call(t,e):0}),e=e.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(e){var t=e.split("!");return t[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(e){var t=e.split("!"),i=t[1]?t[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(e){var t=e.split(":");return t[1]||""},EPUBJS.EpubCFI.prototype.parse=function(e){var t,i,n,r,o,s,a,h,c,u={},p=function(e){var t,i,n,r;return t="element",i=parseInt(e)/2-1,n=e.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:t,index:i,id:r||!1}};return"string"!=typeof e?{spinePos:-1}:(u.str=e,0===e.indexOf("epubcfi(")&&")"===e[e.length-1]&&(e=e.slice(8,e.length-1)),i=this.getChapterComponent(e),n=this.getPathComponent(e)||"",r=this.getCharecterOffsetComponent(e),i?(t=i.split("/")[2]||"")?(u.spinePos=parseInt(t)/2-1||0,s=t.match(/\[(.*)\]/),u.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),u.steps=[],a.forEach(function(e){var t;e&&(t=p(e),u.steps.push(t))}),c=parseInt(h),isNaN(c)||(c%2===0?u.steps.push(p(h)):u.steps.push({type:"text",index:(c-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(u.characterOffset=parseInt(r.split("[")[0]),u.textLocationAssertion=o[1]):u.characterOffset=parseInt(r),u):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(e,t,i){var n,r,o,s,a=t||document,h=i||this.createMarker(a);return"string"==typeof e&&(e=this.parse(e)),r=e.steps[e.steps.length-1],-1===e.spinePos?!1:(n=this.findParent(e,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],e.characterOffset?(s=o.splitText(e.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(e){var t=e||document,i=t.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(e,t){e.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=e.nextSibling,prevSib=e.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,e.parentNode.removeChild(nextSib)),e.parentNode.removeChild(e)):e.classList.contains("EPUBJS-CFI-MARKER")&&e.parentNode.removeChild(e)},EPUBJS.EpubCFI.prototype.findParent=function(e,t){var i,n,r,o=t||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof e&&(e=this.parse(e)),n=e.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,e.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(e,t){if("string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),"string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),e.spinePos>t.spinePos)return 1;if(e.spinePost.steps[i].index)return 1;if(e.steps[i].indext.characterOffset?1:e.characterOffset=0?(o=r.length,e.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(e=n.promise,n.resolve()),e},EPUBJS.Infinite=function(e,t){this.container=e,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=500,this.views=[],this.axis=t,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.displaying?("vertical"===this.axis?this.checkTop():this.checkLeft(),this.trigger("scroll",{top:this.container.scrollTop,left:this.container.scrollLeft}),this.scrolled=!1):(this.displaying=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.checkTop=function(){var e=this.container.scrollTop,t=this.container.scrollHeight,i=e-this.prevScrollTop,n=this.container.getBoundingClientRect().height,r=e+this.offset>t-n,o=e0?this.forwards():o&&0>i&&this.backwards(),this.prevScrollTop=e,e},EPUBJS.Infinite.prototype.checkLeft=function(){var e=this.container.scrollLeft,t=this.container.scrollWidth,i=e-this.prevscrollLeft,n=this.container.getBoundingClientRect().width,r=e+this.offset>t-n,o=e0?this.forwards():o&&0>i&&this.backwards(),this.prevscrollLeft=e,e},EPUBJS.Infinite.prototype.scrollBy=function(e,t,i){i&&(this.displaying=!0),this.container.scrollLeft+=e,this.container.scrollTop+=t,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(e,t,i){i&&(this.displaying=!0),this.container.scrollLeft=e,this.container.scrollTop=t,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(e,t,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=Math.floor(t),c=Math.floor(h/8),u=n>=0?n:c%2===0?c:c-1;return this.documentElement=e,this.spreadWidth=h+u,e.style.overflow="hidden",e.style.width=h+"px",e.style.height=i+"px",e.style[r]="horizontal",e.style[a]="auto",e.style[s]=h+"px",e.style[o]=u+"px",this.colWidth=h,this.gap=u,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var e,t;return this.documentElement.style.width="auto",e=this.documentElement.scrollWidth,t=Math.ceil(e/this.spreadWidth),{displayedPages:t,pageCount:t}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(e,t,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=2,c=Math.floor(t),u=c%2===0?c:c-1,p=Math.floor(u/8),l=n>=0?n:p%2===0?p:p-1,d=Math.floor((u-l)/h);return this.spreadWidth=(d+l)*h,e.document.documentElement.style.overflow="hidden",e.document.body.style.width=u+"px",e.document.body.style.height=i+"px",e.document.body.style[r]="horizontal",e.document.body.style[a]="auto",e.document.body.style[o]=l+"px",e.document.body.style[s]=d+"px",this.colWidth=d,this.gap=l,e.iframe.style.width=d+"px",e.iframe.style.paddingRight=l+"px",{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var e=this.documentElement.scrollWidth,t=Math.ceil(e/this.spreadWidth);return this.documentElement.style.width=e+this.spreadWidth+"px",{displayedPages:t,pageCount:2*t}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(e){var t,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=e.querySelector("[name=viewport");return this.documentElement=e,s&&s.hasAttribute("content")&&(t=s.getAttribute("content"),i=t.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),e.style.width=n+"px"||"auto",e.style.height=r+"px"||"auto",e.style[o]="auto",e.style.overflow="auto",this.colWidth=n,this.gap=0,{pageWidth:n,pageHeight:r}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(e,t){var i=this,n=new EPUBJS.Parser,r=t||EPUBJS.core.request;this.package=e,this.toc=[],this.tocByHref={},this.tocById={},e.navPath&&(this.navUrl=e.baseUrl+e.navPath,this.nav={},this.nav.load=function(){var e=new RSVP.defer,t=e.promise;return r(i.navUrl,"xml").then(function(t){i.toc=n.nav(t),i.loaded(i.toc),e.resolve(i.toc)}),t}),e.ncxPath&&(this.ncxUrl=e.baseUrl+e.ncxPath,this.ncx={},this.ncx.load=function(){var e=new RSVP.defer,t=e.promise;return r(i.ncxUrl,"xml").then(function(t){i.toc=n.ncx(t),i.loaded(i.toc),e.resolve(i.toc)}),t})},EPUBJS.Navigation.prototype.load=function(e){{var t,i;e||EPUBJS.core.request}return this.nav?t=this.nav.load():this.ncx?t=this.ncx.load():(i=new RSVP.defer,i.resolve([]),t=i.promise),t},EPUBJS.Navigation.prototype.loaded=function(e){for(var t,i=0;i=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,c=a.querySelector("content"),u=c.getAttribute("src"),p=a.querySelector("navLabel"),l=p.textContent?p.textContent:"",d=u.split("#"),f=(d[0],t(a));n.unshift({id:h,href:u,label:l,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=e.querySelector("navMap");return i?t(i):[]},EPUBJS.Renderer=function(e,t){var i=t||{};this.settings={infinite:"undefined"==typeof i.infinite?!0:i.infinite,hidden:"undefined"==typeof i.hidden?!1:i.hidden,axis:i.axis||"vertical",viewsLimit:i.viewsLimit||5,width:"undefined"==typeof i.width?!1:i.width,height:"undefined"==typeof i.height?!1:i.height,overflow:"undefined"==typeof i.overflow?"auto":i.overflow,padding:i.padding||""},this.book=e,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.filling=!1,this.displaying=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(e){{var t=e||{},i=t.height!==!1?t.height:"100%",n=t.width!==!1?t.width:"100%";t.hidden||!1}return t.height&&EPUBJS.core.isNumber(t.height)&&(i=t.height+"px"),t.width&&EPUBJS.core.isNumber(t.width)&&(n=t.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis),this.infinite.on("scroll",this.checkCurrent.bind(this))),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=n,this.container.style.height=i,this.container.style.overflow=this.settings.overflow,t.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(e,t){var i=e,n=t,r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=i-o.left-o.right,a=n-o.top-o.bottom;e||(i=window.innerWidth),t||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(e){"vertical"===this.settings.axis?e.resize(s,0):e.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var e=this.element.getBoundingClientRect();this.resize(e.width,e.height)},EPUBJS.Renderer.prototype.attachTo=function(e){var t;return EPUBJS.core.isElement(e)?this.element=e:"string"==typeof e&&(this.element=document.getElementById(e)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(t=this.element.getBoundingClientRect(),this.resize(t.width,t.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var e=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&e0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),this.hooks.replacements.register(this.replacements.bind(this)),this.hooks.display.register(this.afterDisplay.bind(this)),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(e){e.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(e){var t=new RSVP.defer,i=t.promise;return"string"==typeof e&&(e=e.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(e);this.displaying=!0,n?(this.clear(),i=this.render(n),this.settings.infinite&&i.then(function(){return this.fill.call(this)}.bind(this)),i.then(function(){this.trigger("displayed",n),this.displaying=!1,t.resolve(this)}.bind(this))):t.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(e){var t,i,n=this.container.getBoundingClientRect(),r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=n.width-o.left-o.right,a=n.height-o.top-o.bottom;return e?(i=new EPUBJS.View(e),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,e.index),t=i.render(this.book.request),t.then(function(){return this.hooks.display.trigger(i)}.bind(this)).then(function(){return this.hooks.replacements.trigger(i,this)}.bind(this)).then(function(){return i.expand()}.bind(this)).then(function(){return this.rendering=!1,i.show(),this.trigger("rendered",i.section),i}.bind(this)).catch(function(e){this.trigger("loaderror",e)}.bind(this))):(t=new RSVP.defer,t.reject(new Error("No Section Provided")),t.promise)},EPUBJS.Renderer.prototype.forwards=function(){var e,t,i;return e=this.last().section.index+1,this.rendering||e===this.book.spine.length?(t=new RSVP.defer,t.reject(new Error("Reject Forwards")),t.promise):(this.rendering=!0,i=this.book.spine.get(e),t=this.render(i),t.then(function(){var e=this.first(),t=e.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-t.height>100&&(this.remove(e),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-t.height,!0):this.infinite.scrollTo(n-t.width,!0))),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.backwards=function(){var e,t,i;return e=this.first().section.index-1,this.rendering||0>e?(t=new RSVP.defer,t.reject(new Error("Reject Backwards")),t.promise):(this.rendering=!0,i=this.book.spine.get(e),t=this.render(i),t.then(function(){var e;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(e=this.last(),this.remove(e),this.container.scrollTop-this.first().bounds().height>100&&this.remove(e)),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.first().section.index-1,t=this.forwards();return this.filling=!0,"vertical"===this.settings.axis?t.then(this.fillVertical.bind(this)):t.then(this.fillHorizontal.bind(this)),e>0&&t.then(this.backwards.bind(this)),t.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var e=this.container.getBoundingClientRect().height,t=this.last().bounds().bottom,i=new RSVP.defer;return e&&t&&e>t?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var e=this.container.getBoundingClientRect().width,t=this.last().bounds().right,i=new RSVP.defer;return e&&t&&e>=t?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(e){this.views.push(e),e.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(e){this.views.unshift(e),e.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(e,t){this.first()?t-this.first().section.index>=0?this.append(e):t-this.last().section.index<=0&&this.prepend(e):this.append(e)},EPUBJS.Renderer.prototype.remove=function(e){var t=this.views.indexOf(e);e.destroy(),t>-1&&this.views.splice(t,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(e,t){for(var i=new RSVP.defer,n=e.document.querySelectorAll("a[href]"),r=function(e){var i=e.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?e.setAttribute("target","_blank"):0===i.indexOf("#")||(e.onclick=function(){return t.display(i),!1})},o=0;o=0;r--)if(e=this.views[r],t=e.bounds().top,t-1?(delete this.spineByHref[e.href],delete this.spineById[e.idref],this.spineItems.splice(t,1)):void 0},EPUBJS.View=function(e){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.rendering=new RSVP.defer,this.rendered=this.rendering.promise,this.section=e},EPUBJS.View.prototype.create=function(e,t){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,e&&(this.iframe.style.width=e+"px"),t&&(this.iframe.style.height=t+"px"),this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resize=function(e,t){e&&(this.iframe.style.width=e+"px"),t&&(this.iframe.style.height=t+"px"),this.resizing||(this.resizing=!0,this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:(console.log("resize"),this.expand())},EPUBJS.View.prototype.render=function(e){return this.section.render(e).then(function(e){return this.load(e)}.bind(this)).then(this.display.bind(this)).then(function(){this.rendering.resolve(this)}.bind(this))},EPUBJS.View.prototype.load=function(e){var t=new RSVP.defer,i=t.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,t.resolve(this)}.bind(this)),this.document.open(),this.document.write(e),this.document.close(),i):(t.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.display=function(){var e=new RSVP.defer,t=e.promise;return this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),e.resolve(this),t},EPUBJS.View.prototype.expand=function(e,t){var i,n,r,o=e||new RSVP.defer,s=o.promise,a=t||0;return this.resizing=!0,i=this.document.body.getBoundingClientRect(),(!i||0===i.height&&0===i.width)&&console.error("View not shown"),r=i.height,n=this.document.documentElement.scrollWidth,this.width!=n||this.height!=r?setTimeout(function(){this.expand(o,a)}.bind(this),10):o.resolve(),this.width=n,this.height=r,this.iframe.style.height=r+"px",this.iframe.style.width=n+"px",s},EPUBJS.View.prototype.observe=function(e){var t=this,i=new MutationObserver(function(){t.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(e,n),i},EPUBJS.View.prototype.appendTo=function(e){this.element=e,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(e){this.element=e,e.insertBefore(this.iframe,e.firstChild)},EPUBJS.View.prototype.show=function(){this.iframe.style.display="inline-block",this.iframe.style.visibility="visible"},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden"},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)}; \ No newline at end of file +"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(t){"use strict";var e=function(t){return new EPUBJS.Book(t)};e.Render={register:function(t,i){e.Render[t]=i}},"object"==typeof exports?(t.RSVP=require("rsvp"),module.exports=e):"function"==typeof define&&define.amd?define(e):t.ePub=e}(this),function(){"use strict";function t(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function e(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}function i(t,e){return"onerror"===t?(Y.on("error",e),void 0):2!==arguments.length?Y[t]:(Y[t]=e,void 0)}function n(t){return"function"==typeof t||"object"==typeof t&&null!==t}function r(t){return"function"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(){}function a(){}function h(t){try{return t.then}catch(e){return oe.error=e,oe}}function c(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function p(t,e,i){Y.async(function(t){var n=!1,r=c(i,e,function(i){n||(n=!0,e!==i?u(t,i):g(t,i))},function(e){n||(n=!0,y(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,y(t,r))},t)}function l(t,e){e._state===ne?g(t,e._result):t._state===re?y(t,e._result):m(e,void 0,function(i){e!==i?u(t,i):g(t,i)},function(e){y(t,e)})}function d(t,e){if(e.constructor===t.constructor)l(t,e);else{var i=h(e);i===oe?y(t,oe.error):void 0===i?g(t,e):r(i)?p(t,e,i):g(t,e)}}function u(t,e){t===e?g(t,e):n(e)?d(t,e):g(t,e)}function f(t){t._onerror&&t._onerror(t._result),v(t)}function g(t,e){t._state===ie&&(t._result=e,t._state=ne,0===t._subscribers.length?Y.instrument&&ee("fulfilled",t):Y.async(v,t))}function y(t,e){t._state===ie&&(t._state=re,t._result=e,Y.async(f,t))}function m(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+ne]=i,r[o+re]=n,0===o&&t._state&&Y.async(v,t)}function v(t){var e=t._subscribers,i=t._state;if(Y.instrument&&ee(i===ne?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;sa;a++)s[a]=t[a];for(n=0;nn;n++)i[n-1]=t[n];return i}function F(t,e){return{then:function(i,n){return t.call(e,i,n)}}}function I(t,e,i,n){var r=k(i,n,e);return r===ge&&y(t,r.value),t}function N(t,e,i,n){return fe.all(e).then(function(e){var r=k(i,n,e);return r===ge&&y(t,r.value),t})}function V(t){return t&&"object"==typeof t?t.constructor===fe?!0:C(t):!1}function A(t,e,i){this._superConstructor(t,e,!1,i)}function O(t,e,i){this._superConstructor(t,e,!0,i)}function L(t,e,i){this._superConstructor(t,e,!1,i)}function q(){return function(){process.nextTick(H)}}function z(){var t=0,e=new Ie(H),i=document.createTextNode("");return e.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}function M(){var t=new MessageChannel;return t.port1.onmessage=H,function(){t.port2.postMessage(0)}}function j(){return function(){setTimeout(H,1)}}function H(){for(var t=0;_e>t;t+=2){var e=Ve[t],i=Ve[t+1];e(i),Ve[t]=void 0,Ve[t+1]=void 0}_e=0}function W(t,e){Y.async(t,e)}function D(){Y.on.apply(Y,arguments)}function X(){Y.off.apply(Y,arguments)}var K={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(i,n){var r,o=e(this);r=o[i],r||(r=o[i]=[]),-1===t(r,n)&&r.push(n)},off:function(i,n){var r,o,s=e(this);return n?(r=s[i],o=t(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(t,i){var n,r,o=e(this);if(n=o[t])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof t)throw new TypeError("Argument must be an object");return s.prototype=t,new s},te=[],ee=function(t,e,i){1===te.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:Z(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;en;n++)this._eachEntry(i[n],n)},b.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;o(t)?t.constructor===i&&t._state!==ie?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(ne,e,t))},b.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===ie&&(this._remaining--,this._abortOnReject&&t===re?y(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&g(n,this._result)},b.prototype._makeResult=function(t,e,i){return i},b.prototype._willSettleAt=function(t,e){var i=this;m(t,void 0,function(t){i._settledAt(ne,e,t)},function(t){i._settledAt(re,e,t)})};var he=function(t,e){return new ae(this,t,!0,e).promise},ce=function(t,e){function i(t){u(o,t)}function n(t){y(o,t)}var r=this,o=new r(a,e);if(!Q(t))return y(o,new TypeError("You must pass an array to race.")),o;for(var s=t.length,h=0;o._state===ie&&s>h;h++)m(r.resolve(t[h]),void 0,i,n);return o},pe=function(t,e){var i=this;if(t&&"object"==typeof t&&t.constructor===i)return t;var n=new i(a,e);return u(n,t),n},le=function(t,e){var i=this,n=new i(a,e);return y(n,t),n},de="rsvp_"+Z()+"-",ue=0,fe=x;x.cast=pe,x.all=he,x.race=ce,x.resolve=pe,x.reject=le,x.prototype={constructor:x,_guidKey:de,_onerror:function(t){Y.trigger("error",t)},then:function(t,e,i){var n=this,r=n._state;if(r===ne&&!t||r===re&&!e)return Y.instrument&&ee("chained",this,this),this;n._onerror=null;var o=new this.constructor(a,i),s=n._result;if(Y.instrument&&ee("chained",n,o),r){var h=arguments[r-1];Y.async(function(){S(r,o,h,s)})}else m(n,o,t,e);return o},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}};var ge=new R,ye=new R,me=function(t,e){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,h=0;r>h;++h){if(i=arguments[h],!s){if(s=V(i),s===ye){var c=new fe(a);return y(c,ye.value),c}s&&s!==!0&&(i=F(s,i))}o[h]=i}var p=new fe(a);return o[r]=function(t,i){t?y(p,t):void 0===e?u(p,i):e===!0?u(p,T(arguments)):Q(e)?u(p,_(arguments,e)):u(p,i)},s?N(p,o,t,n):I(p,o,t,n)};return i.__proto__=t,i},ve=function(t,e){return fe.all(t,e)};A.prototype=$(ae.prototype),A.prototype._superConstructor=ae,A.prototype._makeResult=B,A.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var we=function(t,e){return new A(fe,t,e).promise},Ee=function(t,e){return fe.race(t,e)},Se=O;O.prototype=$(ae.prototype),O.prototype._superConstructor=ae,O.prototype._init=function(){this._result={}},O.prototype._validateInput=function(t){return t&&"object"==typeof t},O.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},O.prototype._enumerate=function(){var t=this.promise,e=this._input,i=[];for(var n in e)t._state===ie&&e.hasOwnProperty(n)&&i.push({position:n,entry:e[n]});var r=i.length;this._remaining=r;for(var o,s=0;t._state===ie&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var Pe=function(t,e){return new Se(fe,t,e).promise};L.prototype=$(Se.prototype),L.prototype._superConstructor=ae,L.prototype._makeResult=B,L.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var Be,be=function(t,e){return new L(fe,t,e).promise},Ue=function(t){throw setTimeout(function(){throw t}),t},Je=function(t){var e={};return e.promise=new fe(function(t,i){e.resolve=t,e.reject=i},t),e},xe=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as map's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i)})},Re=function(t,e){return fe.resolve(t,e)},Ce=function(t,e){return fe.reject(t,e)},ke=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as filter's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i).then(function(e){for(var i=new Array(n),r=0,o=0;n>o;o++)e[o]&&(i[r]=t[o],r++);return i.length=r,i})})},_e=0,Te=function(t,e){Ve[_e]=t,Ve[_e+1]=e,_e+=2,2===_e&&Be()},Fe="undefined"!=typeof window?window:{},Ie=Fe.MutationObserver||Fe.WebKitMutationObserver,Ne="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Ve=new Array(1e3);Be="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?q():Ie?z():Ne?M():j(),Y.async=Te;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Ae=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Oe in Ae)Ae.hasOwnProperty(Oe)&&D(Oe,Ae[Oe])}var Le={race:Ee,Promise:fe,allSettled:we,hash:Pe,hashSettled:be,denodeify:me,on:D,off:X,map:xe,filter:ke,resolve:Re,reject:Ce,all:ve,rethrow:Ue,defer:Je,EventTarget:K,configure:i,async:W};"function"==typeof define&&define.amd?define(function(){return Le}):"undefined"!=typeof module&&module.exports?module.exports=Le:"undefined"!=typeof this&&(this.RSVP=Le)}.call(this),EPUBJS.Book=function(t){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,e.directory)):this.url=e.directory,i=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+s,i=this.request(this.containerUrl).then(function(t){return r.container(t)}).then(function(e){var i=EPUBJS.core.uri(e.packagePath);return o.packageUrl=t+e.packagePath,o.url=t+i.directory,o.encoding=e.encoding,o.request(o.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(t)})),i.then(function(t){o.unpack(t),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(t){console.error(t.message,t.stack),o.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,i=new EPUBJS.Parser;e.package=i.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){return this.rendition=new EPUBJS.Rendition(this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.Continuous=function(){this.views=[],this.container=container,this.limit=limit||4},EPUBJS.Continuous.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element()),t.onDisplayed=function(){var t,e=this.views.indexOf(t),i=t.section.next();e+1===this.views.length&&i&&(t=new EPUBJS.View(i),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onDisplayed=function(){var t,e=(this.views.indexOf(t),t.section.prev());e&&(t=new EPUBJS.View(e),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.fill=function(t){this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=function(){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(e=new EPUBJS.View(n),this.append(e)),0===o&&r&&(i=new EPUBJS.View(r),this.append(i)),this.resizeView(t)}.bind(this)},EPUBJS.Continuous.prototype.insert=function(t,e){this.views.splice(e,0,t),e-1&&this.views.splice(e,1)},EPUBJS.Continuous.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Continuous.prototype.first=function(){return this.views[0]},EPUBJS.Continuous.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Continuous.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Continuous.prototype.check=function(){{var t=this.container.getBoundingClientRect();(function(e){var i=e.bounds();i.bottom>=t.top&&!(i.top>t.bottom)&&i.right>=t.left&&!(i.left>t.right)?(console.log("visible",e.index),this.resizeView(e),this.display(e)):(console.log("off screen",e.index),e.destroy())}).bind(this)}this.views.forEach(this.isVisible)},EPUBJS.Continuous.prototype.displayView=function(t){return t.display(this.book.request).then(function(){return this.hooks.display.trigger(t)}.bind(this)).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return t.expand()}.bind(this)).then(function(){return this.rendering=!1,t.show(),this.trigger("rendered",section),t}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Continuous.prototype.resizeView=function(t){var e=this.container.getBoundingClientRect(),i=window.getComputedStyle(this.container),n={left:parseFloat(i["padding-left"])||0,right:parseFloat(i["padding-right"])||0,top:parseFloat(i["padding-top"])||0,bottom:parseFloat(i["padding-bottom"])||0},r=e.width-n.left-n.right,o=e.height-n.top-n.bottom,s=100,a=200;"vertical"===this.settings.axis?t.resize(r,s):t.resize(a,o)},EPUBJS.core={},EPUBJS.core.request=function(t,e,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var t;t="xml"==e?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==e?JSON.parse(this.response):"blob"==e?s?this.response:new Blob([this.response]):this.response,h.resolve(t)}else h.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,a=s?"blob":"arraybuffer",h=new RSVP.defer,c=new XMLHttpRequest,p=XMLHttpRequest.prototype;"overrideMimeType"in p||Object.defineProperty(p,"overrideMimeType",{value:function(){}}),i&&(c.withCredentials=!0),c.open("GET",t,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==e&&(c.responseType=a),"json"==e&&c.setRequestHeader("Accept","application/json"),"xml"==e&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(t){var e,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:t},o=t.indexOf("://"),s=t.indexOf("?"),a=t.indexOf("#");return-1!=a&&(r.fragment=t.slice(a+1),t=t.slice(0,a)),-1!=s&&(r.search=t.slice(s+1),t=t.slice(0,s),href=t),-1!=o?(r.protocol=t.slice(0,o),e=t.slice(o+3),n=e.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=e.slice(0,n),r.path=e.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=t,r.directory=EPUBJS.core.folder(t),r.base=r.directory),r.filename=t.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(t){var e=t.lastIndexOf("/");if(-1==e)var i="";return i=t.slice(0,e+1)},EPUBJS.core.queue=function(t){var e=[],i=t,n=function(t,i,n){return e.push({funcName:t,args:i,context:n}),e},r=function(){var t;e.length&&(t=e.shift(),i[t.funcName].apply(t.context||i,t.args))},o=function(){for(;e.length;)r()},s=function(){e=[]},a=function(){return e.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(t){return!(!t||1!=t.nodeType)},EPUBJS.core.uuid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e},EPUBJS.core.values=function(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++er;r++)if("undefined"!=typeof document.body.style[e[r]+i])return e[r]+i;return t},EPUBJS.core.defaults=function(t){for(var e=1,i=arguments.length;i>e;e++){var n=arguments[e];for(var r in n)void 0===t[r]&&(t[r]=n[r])}return t},EPUBJS.core.insert=function(t,e,i){var n=EPUBJS.core.locationOf(t,e,i);return e.splice(n,0,t),n},EPUBJS.core.locationOf=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?h:(o=i(e[h],t),a-s===1?o>0?h:h+1:0===o?h:-1===o?EPUBJS.core.locationOf(t,e,i,h,a):EPUBJS.core.locationOf(t,e,i,s,h))},EPUBJS.core.indexOfSorted=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?-1:(o=i(e[h],t),a-s===1?0===o?h:-1:0===o?h:-1===o?EPUBJS.core.indexOfSorted(t,e,i,h,a):EPUBJS.core.indexOfSorted(t,e,i,s,h))},EPUBJS.EpubCFI=function(t){return t?this.parse(t):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(t){var e=[];return t.forEach(function(t){var i="";i+=2*(t.index+1),t.id&&(i+="["+t.id+"]"),e.push(i)}),e.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(t,e){var i=this.pathTo(t),n=this.generatePathComponent(i);return n.length?"epubcfi("+e+"!"+n+"/1:0)":"epubcfi("+e+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(t){for(var e,i=[];t&&null!==t.parentNode&&9!=t.parentNode.nodeType;)e=t.parentNode.children,i.unshift({id:t.id,tagName:t.tagName,index:e?Array.prototype.indexOf.call(e,t):0}),t=t.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(t){var e=t.split("!"),i=e[1]?e[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},EPUBJS.EpubCFI.prototype.parse=function(t){var e,i,n,r,o,s,a,h,c,p={},l=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(p.str=t,0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),i=this.getChapterComponent(t),n=this.getPathComponent(t)||"",r=this.getCharecterOffsetComponent(t),i?(e=i.split("/")[2]||"")?(p.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),p.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),p.steps=[],a.forEach(function(t){var e;t&&(e=l(t),p.steps.push(e))}),c=parseInt(h),isNaN(c)||(c%2===0?p.steps.push(l(h)):p.steps.push({type:"text",index:(c-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(p.characterOffset=parseInt(r.split("[")[0]),p.textLocationAssertion=o[1]):p.characterOffset=parseInt(r),p):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(t,e,i){var n,r,o,s,a=e||document,h=i||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,t.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(t=n.promise,n.resolve()),t},EPUBJS.Infinite=function(t,e){this.container=t,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=500,this.views=[],this.axis=e,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.displaying?("vertical"===this.axis?this.checkTop():this.checkLeft(),this.trigger("scroll",{top:this.container.scrollTop,left:this.container.scrollLeft}),this.scrolled=!1):(this.displaying=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.checkTop=function(){var t=this.container.scrollTop,e=this.container.scrollHeight,i=t-this.prevScrollTop,n=this.container.getBoundingClientRect().height,r=t+this.offset>e-n,o=t0?this.forwards():o&&0>i&&this.backwards(),this.prevScrollTop=t,t},EPUBJS.Infinite.prototype.checkLeft=function(){var t=this.container.scrollLeft,e=this.container.scrollWidth,i=t-this.prevscrollLeft,n=this.container.getBoundingClientRect().width,r=t+this.offset>e-n,o=t0?this.forwards():o&&0>i&&this.backwards(),this.prevscrollLeft=t,t},EPUBJS.Infinite.prototype.scrollBy=function(t,e,i){i&&(this.displaying=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(t,e,i){i&&(this.displaying=!0),this.container.scrollLeft=t,this.container.scrollTop=e,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(t,e,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=Math.floor(e),c=Math.floor(h/8),p=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=h+p,t.style.overflow="hidden",t.style.width=h+"px",t.style.height=i+"px",t.style[r]="horizontal",t.style[a]="auto",t.style[s]=h+"px",t.style[o]=p+"px",this.colWidth=h,this.gap=p,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var t,e;return this.documentElement.style.width="auto",t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth),{displayedPages:e,pageCount:e}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=2,c=Math.floor(e),p=c%2===0?c:c-1,l=Math.floor(p/8),d=n>=0?n:l%2===0?l:l-1,u=Math.floor((p-d)/h);return this.spreadWidth=(u+d)*h,t.document.documentElement.style.overflow="hidden",t.document.body.style.width=p+"px",t.document.body.style.height=i+"px",t.document.body.style[r]="horizontal",t.document.body.style[a]="auto",t.document.body.style[o]=d+"px",t.document.body.style[s]=u+"px",this.colWidth=u,this.gap=d,t.iframe.style.width=u+"px",t.iframe.style.paddingRight=d+"px",{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth); +return this.documentElement.style.width=t+this.spreadWidth+"px",{displayedPages:e,pageCount:2*e}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(t){var e,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=t.querySelector("[name=viewport");return this.documentElement=t,s&&s.hasAttribute("content")&&(e=s.getAttribute("content"),i=e.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),t.style.width=n+"px"||"auto",t.style.height=r+"px"||"auto",t.style[o]="auto",t.style.overflow="auto",this.colWidth=n,this.gap=0,{pageWidth:n,pageHeight:r}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(t,e){var i=this,n=new EPUBJS.Parser,r=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.navUrl,"xml").then(function(e){i.toc=n.nav(e),i.loaded(i.toc),t.resolve(i.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.ncxUrl,"xml").then(function(e){i.toc=n.ncx(e),i.loaded(i.toc),t.resolve(i.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,i;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(i=new RSVP.defer,i.resolve([]),e=i.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,i=0;i=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,c=a.querySelector("content"),p=c.getAttribute("src"),l=a.querySelector("navLabel"),d=l.textContent?l.textContent:"",u=p.split("#"),f=(u[0],e(a));n.unshift({id:h,href:p,label:d,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},EPUBJS.Renderer=function(t,e){var i=e||{};this.settings={infinite:"undefined"==typeof i.infinite?!0:i.infinite,hidden:"undefined"==typeof i.hidden?!1:i.hidden,axis:i.axis||"vertical",viewsLimit:i.viewsLimit||5,width:"undefined"==typeof i.width?!1:i.width,height:"undefined"==typeof i.height?!1:i.height,overflow:"undefined"==typeof i.overflow?"auto":i.overflow,padding:i.padding||"",offset:400},this.book=t,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.filling=!1,this.displaying=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(t){{var e=t||{},i=e.height!==!1?e.height:"100%",n=e.width!==!1?e.width:"100%";e.hidden||!1}return e.height&&EPUBJS.core.isNumber(e.height)&&(i=e.height+"px"),e.width&&EPUBJS.core.isNumber(e.width)&&(n=e.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis),this.infinite.on("scroll",this.checkCurrent.bind(this))),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=n,this.container.style.height=i,this.container.style.overflow=this.settings.overflow,e.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(t,e){var i=t,n=e,r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=i-o.left-o.right,a=n-o.top-o.bottom;t||(i=window.innerWidth),e||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(t){"vertical"===this.settings.axis?t.resize(s,0):t.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var t=this.element.getBoundingClientRect();this.resize(t.width,t.height)},EPUBJS.Renderer.prototype.attachTo=function(t){var e;return EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(e=this.element.getBoundingClientRect(),this.resize(e.width,e.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var t=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&t0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),this.hooks.replacements.register(this.replacements.bind(this)),this.hooks.display.register(this.afterDisplay.bind(this)),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(t){var e=new RSVP.defer,i=e.promise;return"string"==typeof t&&(t=t.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(t);this.displaying=!0,n?(this.clear(),i=this.render(n),this.settings.infinite&&i.then(function(){return this.fill.call(this)}.bind(this)),i.then(function(){this.trigger("displayed",n),this.displaying=!1,e.resolve(this)}.bind(this))):e.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(t){var e,i,n=this.container.getBoundingClientRect(),r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=n.width-o.left-o.right,a=n.height-o.top-o.bottom;return t?(i=new EPUBJS.View(t),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,t.index),e=i.render(this.book.request),e.then(function(){return this.hooks.display.trigger(i)}.bind(this)).then(function(){return this.hooks.replacements.trigger(i,this)}.bind(this)).then(function(){return i.expand()}.bind(this)).then(function(){return this.rendering=!1,i.show(),this.trigger("rendered",i.section),i}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))):(e=new RSVP.defer,e.reject(new Error("No Section Provided")),e.promise)},EPUBJS.Renderer.prototype.forwards=function(){var t,e,i;return t=this.last().section.index+1,this.rendering||t===this.book.spine.length?(e=new RSVP.defer,e.reject(new Error("Reject Forwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t=this.first(),e=t.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-e.height>100&&(this.remove(t),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-e.height,!0):this.infinite.scrollTo(n-e.width,!0))),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.backwards=function(){var t,e,i;return t=this.first().section.index-1,this.rendering||0>t?(e=new RSVP.defer,e.reject(new Error("Reject Backwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(t=this.last(),this.remove(t),this.container.scrollTop-this.first().bounds().height>100&&this.remove(t)),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.fill=function(){var t=this.first().section.index-1,e=this.forwards();return this.filling=!0,"vertical"===this.settings.axis?e.then(this.fillVertical.bind(this)):e.then(this.fillHorizontal.bind(this)),t>0&&e.then(this.backwards.bind(this)),e.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var t=this.container.getBoundingClientRect().height,e=this.last().bounds().bottom,i=new RSVP.defer;return t&&e&&t>e?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var t=this.container.getBoundingClientRect().width,e=this.last().bounds().right,i=new RSVP.defer;return t&&e&&t>=e?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(t){this.views.push(t),t.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(t){this.views.unshift(t),t.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(t,e){this.first()?e-this.first().section.index>=0?this.append(t):e-this.last().section.index<=0&&this.prepend(t):this.append(t)},EPUBJS.Renderer.prototype.remove=function(t){var e=this.views.indexOf(t);t.destroy(),e>-1&&this.views.splice(e,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(t,e){for(var i=new RSVP.defer,n=t.document.querySelectorAll("a[href]"),r=function(t){var i=t.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?t.setAttribute("target","_blank"):0===i.indexOf("#")||(t.onclick=function(){return e.display(i),!1})},o=0;o=0;r--)if(t=this.views[r],e=t.bounds().top,e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Rendition.prototype.first=function(){return this.views[0]},EPUBJS.Rendition.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Rendition.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Rendition.prototype.check=function(){var t=this.container.getBoundingClientRect(),e=function(e){var i=e.bounds();i.bottom>=t.top-this.settings.offset&&!(i.top>t.bottom)&&i.right>=t.left&&!(i.left>t.right)?e.shown||(console.log("visible",e.index),this.render(e)):e.shown&&(console.log("off screen",e.index),e.destroy())}.bind(this);this.views.forEach(function(t){e(t)}),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.trim()}.bind(this),250)},EPUBJS.Rendition.prototype.trim=function(){for(var t=0;t0?this.views[t-1].shown:!1,n=t+1-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.View=function(t){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.displaying=new RSVP.defer,this.displayed=this.displaying.promise,this.section=t,this.index=t.index,this.element=document.createElement("div"),this.element.classList.add("epub-view"),this.element.style.display="inline-block",this.element.minHeight="100px",this.shown=!1},EPUBJS.View.prototype.create=function(t,e){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,(t||e)&&this.resize(t,e),this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.element.appendChild(this.iframe),this.iframe},EPUBJS.View.prototype.resize=function(t,e){t&&(this.iframe&&(this.iframe.style.width=t+"px"),this.element.style.minWidth=t+"px"),e&&(this.iframe&&(this.iframe.style.height=e+"px"),this.element.style.minHeight=e+"px"),this.resizing||(this.resizing=!0,this.iframe&&this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.expand()},EPUBJS.View.prototype.display=function(t){return this.shown=!0,this.section.render(t).then(function(t){return this.load(t)}.bind(this)).then(this.afterLoad.bind(this)).then(this.displaying.resolve.call()).then(function(){this.onDisplayed(this)}.bind(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,i=e.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,e.resolve(this)}.bind(this)),this.document.open(),this.document.write(t),this.document.close(),i):(e.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.afterLoad=function(){this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),"loading"===this.document.fonts.status&&(this.document.fonts.onloading=function(){this.expand()}.bind(this)),this.observe&&(this.observer=this.observe(this.document.body))},EPUBJS.View.prototype.expand=function(t,e){var i,n,r,o=t||new RSVP.defer,s=o.promise,a=10,h=e||0;return this.resizing=!0,i=this.document.body.getBoundingClientRect(),(!i||0===i.height&&0===i.width)&&console.error("View not shown"),r=i.height,n=this.document.documentElement.scrollWidth,this.width!=n||this.height!=r?setTimeout(function(){this.expand(o,h)}.bind(this),a):o.resolve(),this.width=n,this.height=r,this.resize(n,r),s},EPUBJS.View.prototype.observe=function(t){var e=this,i=new MutationObserver(function(){e.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(t,n),i},EPUBJS.View.prototype.show=function(){this.iframe.style.display="inline-block",this.iframe.style.visibility="visible"},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden"},EPUBJS.View.prototype.bounds=function(){return this.element.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.iframe&&(this.element.removeChild(this.iframe),this.shown=!1,this.iframe=null)},EPUBJS.ViewManager=function(t){this.views=[],this.container=t},EPUBJS.ViewManager.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element())},EPUBJS.ViewManager.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element(),this.container.firstChild)},EPUBJS.ViewManager.prototype.insert=function(t,e){this.views.splice(e,0,t),ethis.last().index?(this.append(t),e=this.views.length):t.indexb.index?1:a.index-1&&this.views.splice(e,1)},EPUBJS.ViewManager.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.ViewManager.prototype.first=function(){return this.views[0]},EPUBJS.ViewManager.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.ViewManager.prototype.map=function(t){return this.views.map(t)}; \ No newline at end of file diff --git a/examples/basic.html b/examples/basic.html index 18dee2e..9331dc5 100644 --- a/examples/basic.html +++ b/examples/basic.html @@ -25,13 +25,17 @@ position: absolute; top: 0; left: 0; + + } + + #viewer > div { + padding: 0 25% 0 25%; } - #viewer iframe { + #viewer .epub-view { background: white; box-shadow: 0 0 4px #ccc; margin: 10px; - width: calc(60% - 60px) !important; padding: 20px; } @@ -79,8 +83,8 @@