diff --git a/dist/epub.js b/dist/epub.js index 857f3fb..09bb8c7 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -3627,19 +3627,22 @@ EPUBJS.Hook.prototype.trigger = function(){ return executing; }; -EPUBJS.Infinite = function(container, axis){ +EPUBJS.Infinite = function(container, limit){ this.container = container; this.windowHeight = window.innerHeight; this.tick = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; this.scrolled = false; this.ignore = false; - this.displaying = false; - this.offset = 500; - this.views = []; - this.axis = axis; - // this.children = container.children; - // this.renderer = renderer; + + this.tolerance = 100; this.prevScrollTop = 0; + this.prevScrollLeft = 0; + + if(container) { + this.start(); + } + + // TODO: add rate limit if performance suffers }; @@ -3678,22 +3681,38 @@ EPUBJS.Infinite.prototype.backwards = function() { EPUBJS.Infinite.prototype.check = function(){ - if(this.scrolled && !this.displaying) { + if(this.scrolled && !this.ignore) { + scrollTop = this.container.scrollTop; + scrollLeft = this.container.scrollLeft; - if(this.axis === "vertical") { - this.checkTop(); - } else { - this.checkLeft(); - } - this.trigger("scroll", { - top: this.container.scrollTop, - left: this.container.scrollLeft + top: scrollTop, + left: scrollLeft }); + // For snap scrolling + if(scrollTop - this.prevScrollTop > this.tolerance) { + this.forwards(); + } + + if(scrollTop - this.prevScrollTop < -this.tolerance) { + this.backwards(); + } + + if(scrollLeft - this.prevScrollLeft > this.tolerance) { + this.forwards(); + } + + if(scrollLeft - this.prevScrollLeft < -this.tolerance) { + this.backwards(); + } + + this.prevScrollTop = scrollTop; + this.prevScrollLeft = scrollLeft; + this.scrolled = false; } else { - this.displaying = false; + this.ignore = false; this.scrolled = false; } @@ -3701,62 +3720,10 @@ EPUBJS.Infinite.prototype.check = function(){ // setTimeout(this.check.bind(this), 100); }; -EPUBJS.Infinite.prototype.checkTop = function(){ - - var scrollTop = this.container.scrollTop; - var scrollHeight = this.container.scrollHeight; - var direction = scrollTop - this.prevScrollTop; - var height = this.container.getBoundingClientRect().height; - - var up = scrollTop + this.offset > scrollHeight-height; - var down = scrollTop < this.offset; - - // Add to bottom - if(up && direction > 0) { - this.forwards(); - } - // Add to top - else if(down && direction < 0) { - this.backwards(); - } - - // console.log(scrollTop) - this.prevScrollTop = scrollTop; - - return scrollTop; -}; - -EPUBJS.Infinite.prototype.checkLeft = function(){ - - var scrollLeft = this.container.scrollLeft; - - var scrollWidth = this.container.scrollWidth; - - var direction = scrollLeft - this.prevscrollLeft; - - var width = this.container.getBoundingClientRect().width; - - var right = scrollLeft + this.offset > scrollWidth-width; - var left = scrollLeft < this.offset; - - // Add to bottom - if(right && direction > 0) { - this.forwards(); - } - // Add to top - else if(left && direction < 0) { - this.backwards(); - } - - // console.log(scrollTop) - this.prevscrollLeft = scrollLeft; - - return scrollLeft; -}; EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){ if(silent) { - this.displaying = true; + this.ignore = true; } this.container.scrollLeft += x; this.container.scrollTop += y; @@ -3767,7 +3734,7 @@ EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){ EPUBJS.Infinite.prototype.scrollTo = function(x, y, silent){ if(silent) { - this.displaying = true; + this.ignore = true; } this.container.scrollLeft = x; this.container.scrollTop = y; @@ -3782,14 +3749,14 @@ EPUBJS.Infinite.prototype.scrollTo = function(x, y, silent){ // }; this.check(); - }; RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype); EPUBJS.Layout = EPUBJS.Layout || {}; -EPUBJS.Layout.Reflowable = function(){ - this.documentElement = null; +EPUBJS.Layout.Reflowable = function(view){ + // this.documentElement = null; + this.view = view; this.spreadWidth = null; }; @@ -3844,12 +3811,13 @@ EPUBJS.Layout.Reflowable.prototype.calculatePages = function() { }; }; -EPUBJS.Layout.ReflowableSpreads = function(){ - this.documentElement = null; +EPUBJS.Layout.ReflowableSpreads = function(view){ + this.view = view; + this.documentElement = view.document.documentElement; this.spreadWidth = null; }; -EPUBJS.Layout.ReflowableSpreads.prototype.format = function(view, _width, _height, _gap){ +EPUBJS.Layout.ReflowableSpreads.prototype.format = function(_width, _height, _gap){ var columnAxis = EPUBJS.core.prefixed('columnAxis'); var columnGap = EPUBJS.core.prefixed('columnGap'); var columnWidth = EPUBJS.core.prefixed('columnWidth'); @@ -3871,25 +3839,27 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(view, _width, _heigh this.spreadWidth = (colWidth + gap) * divisor; - view.document.documentElement.style.overflow = "hidden"; + this.view.document.documentElement.style.overflow = "hidden"; // Must be set to the new calculated width or the columns will be off - view.document.body.style.width = width + "px"; + this.view.document.body.style.width = width + "px"; //-- Adjust height - view.document.body.style.height = _height + "px"; + this.view.document.body.style.height = _height + "px"; //-- Add columns - view.document.body.style[columnAxis] = "horizontal"; - view.document.body.style[columnFill] = "auto"; - view.document.body.style[columnGap] = gap+"px"; - view.document.body.style[columnWidth] = colWidth+"px"; + this.view.document.body.style[columnAxis] = "horizontal"; + this.view.document.body.style[columnFill] = "auto"; + this.view.document.body.style[columnGap] = gap+"px"; + this.view.document.body.style[columnWidth] = colWidth+"px"; this.colWidth = colWidth; this.gap = gap; - view.iframe.style.width = colWidth+"px"; - view.iframe.style.paddingRight = gap+"px"; + this.view.document.body.style.paddingRight = gap + "px"; + // view.iframe.style.width = this.spreadWidth+"px"; + // this.view.element.style.paddingRight = gap+"px"; + // view.iframe.style.paddingLeft = gap+"px"; return { pageWidth : this.spreadWidth, @@ -3897,12 +3867,12 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(view, _width, _heigh }; }; -EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function() { +EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function(view) { var totalWidth = this.documentElement.scrollWidth; var displayedPages = Math.ceil(totalWidth / this.spreadWidth); //-- Add a page to the width of the document to account an for odd number of pages - this.documentElement.style.width = totalWidth + this.spreadWidth + "px"; + // this.documentElement.style.width = totalWidth + this.spreadWidth + "px"; return { displayedPages : displayedPages, pageCount : displayedPages * 2 @@ -4242,36 +4212,42 @@ EPUBJS.Paginate.prototype.initialize = function(){ this.renderer.hooks.display.register(this.registerLayoutMethod.bind(this)); this.currentPage = 0; + }; EPUBJS.Paginate.prototype.registerLayoutMethod = function(view) { var task = new RSVP.defer(); this.layoutMethod = this.determineLayout({}); - this.layout = new EPUBJS.Layout[this.layoutMethod](); - this.formated = this.layout.format(view, this.settings.width, this.settings.height, this.settings.gap); - - this.renderer.infinite.offset = this.formated.pageWidth; - + this.layout = new EPUBJS.Layout[this.layoutMethod](view); + this.formated = this.layout.format(this.settings.width, this.settings.height, this.settings.gap); + + // Add extra padding for the gap between this and the next view + view.element.style.paddingRight = this.layout.gap+"px"; + + // Set the look ahead offset for what is visible + this.renderer.settings.offset = this.formated.pageWidth; + task.resolve(); return task.promise; }; EPUBJS.Paginate.prototype.page = function(pg){ - this.currentPage = pg; - this.renderer.infinite.scrollTo(this.currentPage * this.formated.pageWidth, 0); - + // this.currentPage = pg; + // this.renderer.infinite.scrollTo(this.currentPage * this.formated.pageWidth, 0); //-- Return false if page is greater than the total // return false; }; EPUBJS.Paginate.prototype.next = function(){ - return this.page(this.currentPage + 1); + this.renderer.infinite.scrollBy(this.formated.pageWidth, 0); + // return this.page(this.currentPage + 1); }; EPUBJS.Paginate.prototype.prev = function(){ - return this.page(this.currentPage - 1); + this.renderer.infinite.scrollBy(-this.formated.pageWidth, 0); + // return this.page(this.currentPage - 1); }; EPUBJS.Paginate.prototype.display = function(what){ @@ -5291,49 +5267,22 @@ EPUBJS.Rendition = function(book, options) { 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.replacements.register(EPUBJS.replace.links.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.silentScroll) { - - this.check(); - - this.scrolled = false; - } else { - this.silentScroll = false; - this.scrolled = false; + if(this.settings.infinite) { + this.infinite = new EPUBJS.Infinite(this.container); + this.infinite.on("scroll", this.check.bind(this)); } - - this.tick.call(window, this.handleScroll.bind(this)); - // setTimeout(this.check.bind(this), 100); + }; /** @@ -5462,7 +5411,6 @@ EPUBJS.Rendition.prototype.display = function(what){ // }.bind(this)); // } this.check(); - this.handleScroll(); view.displayed.then(function(){ this.trigger("displayed", section); @@ -5536,17 +5484,52 @@ EPUBJS.Rendition.prototype.afterDisplayed = function(currView){ prevView = new EPUBJS.View(prev); this.prepend(prevView); } - + + this.removeShownListeners(currView); }; - + +EPUBJS.Rendition.prototype.afterDisplayedAbove = function(currView){ + + var bounds, style, marginTopBottom, marginLeftRight; + var prevTop = this.container.scrollTop; + var prevLeft = this.container.scrollLeft; + + this.afterDisplayed(currView); + + if(currView.countered) return; + + bounds = currView.bounds(); + + if(this.settings.axis === "vertical") { + this.infinite.scrollTo(0, prevTop + bounds.height, true) + } else { + this.infinite.scrollTo(prevLeft + bounds.width, 0, true); + } + + currView.countered = true; + + this.removeShownListeners(currView); + + if(this.afterDisplayedAboveHook) this.afterDisplayedAboveHook(currView); + +}; + +// Remove Previous Listeners if present +EPUBJS.Rendition.prototype.removeShownListeners = function(view){ + + view.off("shown", this.afterDisplayed); + view.off("shown", this.afterDisplayedAbove); + +}; + EPUBJS.Rendition.prototype.append = function(view){ this.views.push(view); // view.appendTo(this.container); this.container.appendChild(view.element); - view.onShown = this.afterDisplayed.bind(this); + view.on("shown", this.afterDisplayed.bind(this)); // this.resizeView(view); }; @@ -5555,33 +5538,8 @@ EPUBJS.Rendition.prototype.prepend = function(view){ // view.prependTo(this.container); this.container.insertBefore(view.element, this.container.firstChild); + view.on("shown", this.afterDisplayedAbove.bind(this)); - - view.onShown = function(currView){ - var bounds, style, marginTopBottom, marginLeftRight; - var prevTop = this.container.scrollTop; - var prevLeft = this.container.scrollLeft; - - this.afterDisplayed(currView); - - if(view.countered) return; - - bounds = currView.bounds(); - style = window.getComputedStyle(currView.element); - marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0; - marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0; - - if(this.settings.axis === "vertical") { - console.log("scroll TO", prevTop, bounds.height + marginTopBottom) - this.scrollTo(0, prevTop + bounds.height + marginTopBottom, true) - } else { - this.scrollTo(prevLeft + bounds.width + marginLeftRight, 0, true); - } - - view.countered = true; - - }.bind(this); - // this.resizeView(view); }; @@ -5596,7 +5554,7 @@ EPUBJS.Rendition.prototype.fill = function(view){ this.container.appendChild(view.element); - view.onShown = this.afterDisplayed.bind(this); + view.on("shown", this.afterDisplayed.bind(this)); }; @@ -5648,46 +5606,44 @@ EPUBJS.Rendition.prototype.each = function(func) { return this.views.forEach(func); }; +EPUBJS.Rendition.prototype.isVisible = function(view, _container){ + var position = view.position(); + var container = _container || this.container.getBoundingClientRect(); + + if((position.bottom >= container.top - this.settings.offset) && + !(position.top > container.bottom) && + (position.right >= container.left) && + !(position.left > container.right + this.settings.offset)) { + // Visible + + // Fit to size of the container, apply padding + // this.resizeView(view); + if(!view.shown && !this.rendering) { + console.log("render", view.index); + this.render(view); + } + + } else { + + if(view.shown) { + // console.log("off screen", view.index); + view.destroy(); + console.log("destroy:", view.section.index) + } + } +}; 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 && !this.rendering) { - console.log("render", 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); - }); + this.isVisible(view, container); + }.bind(this)); clearTimeout(this.trimTimeout); this.trimTimeout = setTimeout(function(){ this.trim(); }.bind(this), 250); + }; EPUBJS.Rendition.prototype.trim = function(){ @@ -5712,53 +5668,20 @@ EPUBJS.Rendition.prototype.erase = function(view, above){ //Trim 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(above) { if(this.settings.axis === "vertical") { - this.scrollTo(0, prevTop - bounds.height - marginTopBottom, true); + this.infinite.scrollTo(0, prevTop - bounds.height, true); } else { - this.scrollTo(prevLeft - bounds.width - marginLeftRight, 0, true); + console.log("remove left:", view.section.index) + this.infinite.scrollTo(prevLeft - bounds.width, 0, true); } } }; -EPUBJS.Rendition.prototype.scrollBy = function(x, y, silent){ - if(silent) { - this.silentScroll = 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.silentScroll = 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(); @@ -5828,9 +5751,93 @@ EPUBJS.Rendition.prototype.onResized = function(e) { this.resize(bounds.width, bounds.height); }; +EPUBJS.Rendition.prototype.paginate = function(options) { + this.pagination = new EPUBJS.Paginate(this, { + width: this.settings.width, + height: this.settings.height + }); + return this.pagination; +}; + +EPUBJS.Renderer.prototype.checkCurrent = function(position) { + var view, top; + var container = this.container.getBoundingClientRect(); + var length = this.views.length - 1; + + if(this.rendering) { + return; + } + + if(this.settings.axis === "horizontal") { + // TODO: Check for current horizontal + } else { + + for (var i = length; i >= 0; i--) { + view = this.views[i]; + top = view.bounds().top; + if(top < container.bottom) { + + if(this.current == view.section) { + break; + } + + this.current = view.section; + this.trigger("current", this.current); + break; + } + } + + } + +}; + //-- Enable binding events to Renderer RSVP.EventTarget.mixin(EPUBJS.Rendition.prototype); +EPUBJS.replace = {}; +EPUBJS.replace.links = function(view, renderer) { + var task = new RSVP.defer(); + var links = view.document.querySelectorAll("a[href]"); + var replaceLinks = function(link){ + var href = link.getAttribute("href"); + var uri = new EPUBJS.core.uri(href); + + + if(uri.protocol){ + + link.setAttribute("target", "_blank"); + + }else{ + + // relative = EPUBJS.core.resolveUrl(directory, href); + // if(uri.fragment && !base) { + // link.onclick = function(){ + // renderer.fragment(href); + // return false; + // }; + // } else { + + //} + + if(href.indexOf("#") === 0) { + // do nothing with fragment yet + } else { + link.onclick = function(){ + renderer.display(href); + return false; + }; + } + + } + }; + + for (var i = 0; i < links.length; i++) { + replaceLinks(links[i]); + } + + task.resolve(); + return task.promise; +}; EPUBJS.Section = function(item){ this.idref = item.idref; this.linear = item.linear; @@ -6040,6 +6047,8 @@ EPUBJS.View = function(section) { this.shown = false; this.rendered = false; + + this.observe = false; }; EPUBJS.View.prototype.create = function(width, height) { @@ -6075,15 +6084,15 @@ EPUBJS.View.prototype.resize = function(width, height) { if(width){ if(this.iframe) { this.iframe.style.width = width + "px"; + this.element.style.width = width + "px"; } - // this.element.style.width = width + "px"; } if(height){ if(this.iframe) { this.iframe.style.height = height + "px"; + this.element.style.height = height + "px"; } - // this.element.style.height = height + "px"; } if (!this.resizing) { @@ -6091,14 +6100,16 @@ EPUBJS.View.prototype.resize = function(width, height) { if(this.iframe) { this.expand(); } - } + } }; EPUBJS.View.prototype.resized = function(e) { if (!this.resizing) { - this.expand(); + if(this.iframe) { + // this.expand(); + } } else { this.resizing = false; } @@ -6165,7 +6176,7 @@ EPUBJS.View.prototype.afterLoad = function() { // Wait for fonts to load to finish if(this.document.fonts.status === "loading") { this.document.fonts.onloading = function(){ - this.expand(); + // this.expand(); }.bind(this); } @@ -6180,13 +6191,14 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { var width, height; var expanding = _defer || new RSVP.defer(); var expanded = expanding.promise; - var fontsLoading = false; - + // var fontsLoading = false; // Stop checking for equal height after 10 tries var MAX = 10; - var TIMEOUT = 10; - var count = _count || 0; - + var count = _count || 1; + var TIMEOUT = 10 * _count; + + // console.log("expand", count, this.index) + // Flag Changes this.resizing = true; @@ -6205,10 +6217,10 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { height = bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle? width = this.document.documentElement.scrollWidth; - - if(this.width != width || this.height != height) { + if(count <= MAX && (this.width != width || this.height != height)) { setTimeout(function(){ + count += 1; this.expand(expanding, count); }.bind(this), TIMEOUT); @@ -6256,10 +6268,6 @@ EPUBJS.View.prototype.observe = function(target) { // element.insertBefore(this.iframe, element.firstChild); // }; -EPUBJS.View.prototype.onShown = function() { - // Noop -- replace me -}; - EPUBJS.View.prototype.show = function() { // this.iframe.style.display = "block"; this.element.style.width = this.width + "px"; @@ -6268,7 +6276,8 @@ EPUBJS.View.prototype.show = function() { this.iframe.style.display = "inline-block"; this.iframe.style.visibility = "visible"; - this.onShown(this); + this.trigger("shown", this); + this.shown = true; }; @@ -6276,27 +6285,41 @@ EPUBJS.View.prototype.show = function() { EPUBJS.View.prototype.hide = function() { this.iframe.style.display = "none"; this.iframe.style.visibility = "hidden"; - // this.shown = false; + this.trigger("hidden"); +}; +EPUBJS.View.prototype.position = function() { + return this.element.getBoundingClientRect(); }; EPUBJS.View.prototype.bounds = function() { - return this.element.getBoundingClientRect(); + var bounds = this.element.getBoundingClientRect(); + var style = window.getComputedStyle(this.element); + var marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0; + var marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0; + var borderTopBottom = parseInt(style.borderTop) + parseInt(style.borderBottom) || 0; + var borderLeftRight = parseInt(style.borderLeft) + parseInt(style.borderRight) || 0; + + return { + height: bounds.height + marginTopBottom + borderTopBottom, + width: bounds.width + marginLeftRight + borderLeftRight + } }; EPUBJS.View.prototype.destroy = function() { // Stop observing // this.observer.disconnect(); + if(this.iframe){ this.element.removeChild(this.iframe); this.shown = false; this.iframe = null; } - this.element.style.height = 0; - this.element.style.width = 0; + // this.element.style.height = 0; + // this.element.style.width = 0; }; - +RSVP.EventTarget.mixin(EPUBJS.View.prototype); // View Management EPUBJS.ViewManager = function(container){ this.views = []; diff --git a/dist/epub.min.js b/dist/epub.min.js index bb1be83..764ab41 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,3 +1,3 @@ -"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(t){var e,i;!function(){var t={},n={};e=function(e,i,n){t[e]={deps:i,callback:n}},i=function(e){function r(t){if("."!==t.charAt(0))return t;for(var i=t.split("/"),n=e.split("/").slice(0,-1),r=0,o=i.length;o>r;r++){var s=i[r];if(".."===s)n.pop();else{if("."===s)continue;n.push(s)}}return n.join("/")}if(n[e])return n[e];if(n[e]={},!t[e])throw new Error("Could not find module "+e);for(var o,s=t[e],a=s.deps,h=s.callback,c=[],l=0,u=a.length;u>l;l++)c.push("exports"===a[l]?o={}:i(r(a[l])));var p=h.apply(this,c);return n[e]=o||p},i.entries=t}(),e("rsvp/-internal",["./utils","./instrument","./config","exports"],function(t,e,i,n){"use strict";function r(){}function o(t){try{return t.then}catch(e){return J.error=e,J}}function s(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function a(t,e,i){b.async(function(t){var n=!1,r=s(i,e,function(i){n||(n=!0,e!==i?l(t,i):p(t,i))},function(e){n||(n=!0,d(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,d(t,r))},t)}function h(t,e){t._onerror=null,e._state===U?p(t,e._result):t._state===x?d(t,e._result):f(e,void 0,function(i){e!==i?l(t,i):p(t,i)},function(e){d(t,e)})}function c(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===J?d(t,J.error):void 0===i?p(t,e):S(i)?a(t,e,i):p(t,e)}}function l(t,e){t===e?p(t,e):E(e)?c(t,e):p(t,e)}function u(t){t._onerror&&t._onerror(t._result),g(t)}function p(t,e){t._state===B&&(t._result=e,t._state=U,0===t._subscribers.length?b.instrument&&P("fulfilled",t):b.async(g,t))}function d(t,e){t._state===B&&(t._state=x,t._result=e,b.async(u,t))}function f(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+U]=i,r[o+x]=n,0===o&&t._state&&b.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(b.instrument&&P(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=u[t],i=u[t+1];e(i),u[t]=void 0,u[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){u[s]=t,u[s+1]=e,s+=2,2===s&&a()};var a,h="undefined"!=typeof window?window:{},c=h.MutationObserver||h.WebKitMutationObserver,l="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,u=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():c?i():l?n():r()}),e("rsvp/config",["./events","exports"],function(t,e){"use strict";function i(t,e){return"onerror"===t?void r.on("error",e):2!==arguments.length?r[t]:void(r[t]=e)}var n=t["default"],r={instrument:!1};n.mixin(r),e.config=r,e.configure=i}),e("rsvp/defer",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t){var e={};return e.promise=new i(function(t,i){e.resolve=t,e.reject=i},t),e}}),e("rsvp/enumerator",["./utils","./-internal","exports"],function(t,e,i){"use strict";function n(t,e,i){return t===u?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(t,e,i,n){this._instanceConstructor=t,this.promise=new t(a,n),this._abortOnReject=i,this._validateInput(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._init(),0===this.length?c(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&c(this.promise,this._result))):h(this.promise,this._validationError())}var o=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,c=e.fulfill,l=e.subscribe,u=e.FULFILLED,p=e.REJECTED,d=e.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(t){return o(t)},r.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},r.prototype._init=function(){this._result=new Array(this.length)},i["default"]=r,r.prototype._enumerate=function(){for(var t=this.length,e=this.promise,i=this._input,n=0;e._state===d&&t>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;s(t)?t.constructor===i&&t._state!==d?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(u,e,t))},r.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&t===p?h(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&c(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;l(t,void 0,function(t){i._settledAt(u,e,t)},function(t){i._settledAt(p,e,t)})}}),e("rsvp/events",["exports"],function(t){"use strict";function e(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function i(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}t["default"]={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(t,n){var r,o=i(this);r=o[t],r||(r=o[t]=[]),-1===e(r,n)&&r.push(n)},off:function(t,n){var r,o,s=i(this);return n?(r=s[t],o=e(r,n),void(-1!==o&&r.splice(o,1))):void(s[t]=[])},trigger:function(t,e){var n,r,o=i(this);if(n=o[t])for(var s=0;sa;a++)s[a]=e(t[a]);return n.all(s,i).then(function(e){for(var i=new Array(o),n=0,r=0;o>r;r++)e[r]&&(i[n]=t[r],n++);return i.length=n,i})})}}),e("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(t,e,i,n,r){"use strict";function o(t,e,i){this._superConstructor(t,e,!1,i)}var s=t["default"],a=e.makeSettledResult,h=i["default"],c=e["default"],l=n.o_create;o.prototype=l(h.prototype),o.prototype._superConstructor=c,o.prototype._makeResult=a,o.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},r["default"]=function(t,e){return new o(s,t,e).promise}}),e("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(t,e,i,n){"use strict";{var r=t["default"],o=e["default"];i.ABORT_ON_REJECTION}n["default"]=function(t,e){return new o(r,t,e).promise}}),e("rsvp/instrument",["./config","./utils","exports"],function(t,e,i){"use strict";var n=t.config,r=e.now,o=[];i["default"]=function(t,e,i){1===o.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:r(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;ea;a++)s[a]=e(t[a]);return n.all(s,i)})}}),e("rsvp/node",["./promise","./utils","exports"],function(t,e,i){"use strict";var n=t["default"],r=e.isArray;i["default"]=function(t,e){function i(){for(var i=arguments.length,r=new Array(i),a=0;i>a;a++)r[a]=arguments[a];var h;return o||s||!e?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=e),n.all(r).then(function(i){function r(n,r){function a(){for(var t=arguments.length,i=new Array(t),a=0;t>a;a++)i[a]=arguments[a];var h=i[0],c=i[1];if(h)r(h);else if(o)n(i.slice(1));else if(s){var l,u,p={},d=i.slice(1);for(u=0;ua;a++)o=i[a],this._eachEntry(o.entry,o.position)}}),e("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(t,e,i,n,r,o,s,a,h,c,l){"use strict";function u(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function p(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(t,e){this._id=C++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),y!==t&&(m(t)||u(),this instanceof d||p(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),m=(n.objectOrFunction,n.isFunction),v=n.now,y=r.noop,w=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,S=r.invokeCallback,P=r.FULFILLED,b=o["default"],B=s["default"],U=a["default"],x=h["default"],J=c["default"],R="rsvp_"+v()+"-",C=0;l["default"]=d,d.cast=b,d.all=B,d.race=U,d.resolve=x,d.reject=J,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,i){var n=this;n._onerror=null;var r=new this.constructor(y,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===P&&t?f.async(function(){S(o,r,t,s)}):w(n,r,t,e),r},"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)}}}),e("rsvp/promise/all",["../enumerator","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return new i(this,t,!0,e).promise}}),e("rsvp/promise/cast",["./resolve","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=i}),e("rsvp/promise/race",["../utils","../-internal","exports"],function(t,e,i){"use strict";var n=t.isArray,r=(t.isFunction,t.isMaybeThenable,e.noop),o=e.resolve,s=e.reject,a=e.subscribe,h=e.PENDING;i["default"]=function(t,e){function i(t){o(u,t)}function c(t){s(u,t)}var l=this,u=new l(r,e);if(!n(t))return s(u,new TypeError("You must pass an array to race.")),u;for(var p=t.length,d=0;u._state===h&&p>d;d++)a(l.resolve(t[d]),void 0,i,c);return u}}),e("rsvp/promise/reject",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.reject;e["default"]=function(t,e){var r=this,o=new r(i,e);return n(o,t),o}}),e("rsvp/promise/resolve",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.resolve;e["default"]=function(t,e){var r=this;if(t&&"object"==typeof t&&t.constructor===r)return t;var o=new r(i,e);return n(o,t),o}}),e("rsvp/race",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.race(t,e)}}),e("rsvp/reject",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.reject(t,e)}}),e("rsvp/resolve",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.resolve(t,e)}}),e("rsvp/rethrow",["exports"],function(t){"use strict";t["default"]=function(t){throw setTimeout(function(){throw t}),t}}),e("rsvp/utils",["exports"],function(t){"use strict";function e(t){return"function"==typeof t||"object"==typeof t&&null!==t}function i(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}t.objectOrFunction=e,t.isFunction=i,t.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var o=r;t.isArray=o;var s=Date.now||function(){return(new Date).getTime()};t.now=s;var a=Object.create||function(t){var e=function(){};return e.prototype=t,e};t.o_create=a}),e("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(t,e,i,n,r,o,s,a,h,c,l,u,p,d,f,g,m){"use strict";function v(t,e){k.async(t,e)}function y(){k.on.apply(k,arguments)}function w(){k.off.apply(k,arguments)}var E=t["default"],S=e["default"],P=i["default"],b=n["default"],B=r["default"],U=o["default"],x=s["default"],J=a["default"],R=h["default"],C=c["default"],k=l.config,_=l.configure,T=u["default"],F=p["default"],I=d["default"],N=f["default"],O=g["default"];if(k.async=O,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var V=window.__PROMISE_INSTRUMENTATION__;_("instrument",!0);for(var A in V)V.hasOwnProperty(A)&&y(A,V[A])}m.Promise=E,m.EventTarget=S,m.all=b,m.allSettled=B,m.race=U,m.hash=x,m.hashSettled=J,m.rethrow=R,m.defer=C,m.denodeify=P,m.configure=_,m.on=y,m.off=w,m.resolve=F,m.reject=I,m.async=v,m.map=T,m.filter=N}),t.RSVP=i("rsvp")}(self),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,l=XMLHttpRequest.prototype;"overrideMimeType"in l||Object.defineProperty(l,"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,l={},u=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}:(l.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]||"")?(l.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),l.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),l.steps=[],a.forEach(function(t){var e;t&&(e=u(t),l.steps.push(e))}),c=parseInt(h),isNaN(c)||l.steps.push(c%2===0?u(h):{type:"text",index:(c-1)/2}),o=r.match(/\[(.*)\]/),o&&o[1]?(l.characterOffset=parseInt(r.split("[")[0]),l.textLocationAssertion=o[1]):l.characterOffset=parseInt(r),l):{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),l=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=h+l,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]=l+"px",this.colWidth=h,this.gap=l,{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),l=c%2===0?c:c-1,u=Math.floor(l/8),p=n>=0?n:u%2===0?u:u-1,d=Math.floor((l-p)/h);return this.spreadWidth=(d+p)*h,t.document.documentElement.style.overflow="hidden",t.document.body.style.width=l+"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]=p+"px",t.document.body.style[s]=d+"px",this.colWidth=d,this.gap=p,t.iframe.style.width=d+"px",t.iframe.style.paddingRight=p+"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"),l=c.getAttribute("src"),u=a.querySelector("navLabel"),p=u.textContent?u.textContent:"",d=l.split("#"),f=(d[0],e(a));n.unshift({id:h,href:l,label:p,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)),void this.hooks.display.register(this.afterDisplay.bind(this))):void console.error("Not an Element")},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,e.then("vertical"===this.settings.axis?this.fillVertical.bind(this):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||this.rendering||(console.log("render",e.index),this.render(e)):e.shown&&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,e=0;e0?this.views[e-1].shown:!1,r=e+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.style.height=0,this.element.style.width=0,this.element.style.overflow="hidden",this.shown=!1,this.rendered=!1},EPUBJS.View.prototype.create=function(t,e){return this.iframe?this.iframe:(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.rendered=!0,this.iframe) -},EPUBJS.View.prototype.resize=function(t,e){t&&this.iframe&&(this.iframe.style.width=t+"px"),e&&this.iframe&&(this.iframe.style.height=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(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"),s):(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.onShown=function(){},EPUBJS.View.prototype.show=function(){this.element.style.width=this.width+"px",this.element.style.height=this.height+"px",this.iframe.style.display="inline-block",this.iframe.style.visibility="visible",this.onShown(this),this.shown=!0},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),this.element.style.height=0,this.element.style.width=0},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 +"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(t){var e,i;!function(){var t={},n={};e=function(e,i,n){t[e]={deps:i,callback:n}},i=function(e){function r(t){if("."!==t.charAt(0))return t;for(var i=t.split("/"),n=e.split("/").slice(0,-1),r=0,o=i.length;o>r;r++){var s=i[r];if(".."===s)n.pop();else{if("."===s)continue;n.push(s)}}return n.join("/")}if(n[e])return n[e];if(n[e]={},!t[e])throw new Error("Could not find module "+e);for(var o,s=t[e],a=s.deps,h=s.callback,c=[],l=0,p=a.length;p>l;l++)c.push("exports"===a[l]?o={}:i(r(a[l])));var u=h.apply(this,c);return n[e]=o||u},i.entries=t}(),e("rsvp/-internal",["./utils","./instrument","./config","exports"],function(t,e,i,n){"use strict";function r(){}function o(t){try{return t.then}catch(e){return J.error=e,J}}function s(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function a(t,e,i){b.async(function(t){var n=!1,r=s(i,e,function(i){n||(n=!0,e!==i?l(t,i):u(t,i))},function(e){n||(n=!0,d(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,d(t,r))},t)}function h(t,e){t._onerror=null,e._state===U?u(t,e._result):t._state===x?d(t,e._result):f(e,void 0,function(i){e!==i?l(t,i):u(t,i)},function(e){d(t,e)})}function c(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===J?d(t,J.error):void 0===i?u(t,e):S(i)?a(t,e,i):u(t,e)}}function l(t,e){t===e?u(t,e):E(e)?c(t,e):u(t,e)}function p(t){t._onerror&&t._onerror(t._result),g(t)}function u(t,e){t._state===B&&(t._result=e,t._state=U,0===t._subscribers.length?b.instrument&&P("fulfilled",t):b.async(g,t))}function d(t,e){t._state===B&&(t._state=x,t._result=e,b.async(p,t))}function f(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+U]=i,r[o+x]=n,0===o&&t._state&&b.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(b.instrument&&P(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=p[t],i=p[t+1];e(i),p[t]=void 0,p[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){p[s]=t,p[s+1]=e,s+=2,2===s&&a()};var a,h="undefined"!=typeof window?window:{},c=h.MutationObserver||h.WebKitMutationObserver,l="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,p=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():c?i():l?n():r()}),e("rsvp/config",["./events","exports"],function(t,e){"use strict";function i(t,e){return"onerror"===t?void r.on("error",e):2!==arguments.length?r[t]:void(r[t]=e)}var n=t["default"],r={instrument:!1};n.mixin(r),e.config=r,e.configure=i}),e("rsvp/defer",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t){var e={};return e.promise=new i(function(t,i){e.resolve=t,e.reject=i},t),e}}),e("rsvp/enumerator",["./utils","./-internal","exports"],function(t,e,i){"use strict";function n(t,e,i){return t===p?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(t,e,i,n){this._instanceConstructor=t,this.promise=new t(a,n),this._abortOnReject=i,this._validateInput(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._init(),0===this.length?c(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&c(this.promise,this._result))):h(this.promise,this._validationError())}var o=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,c=e.fulfill,l=e.subscribe,p=e.FULFILLED,u=e.REJECTED,d=e.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(t){return o(t)},r.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},r.prototype._init=function(){this._result=new Array(this.length)},i["default"]=r,r.prototype._enumerate=function(){for(var t=this.length,e=this.promise,i=this._input,n=0;e._state===d&&t>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;s(t)?t.constructor===i&&t._state!==d?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(p,e,t))},r.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&t===u?h(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&c(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;l(t,void 0,function(t){i._settledAt(p,e,t)},function(t){i._settledAt(u,e,t)})}}),e("rsvp/events",["exports"],function(t){"use strict";function e(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function i(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}t["default"]={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(t,n){var r,o=i(this);r=o[t],r||(r=o[t]=[]),-1===e(r,n)&&r.push(n)},off:function(t,n){var r,o,s=i(this);return n?(r=s[t],o=e(r,n),void(-1!==o&&r.splice(o,1))):void(s[t]=[])},trigger:function(t,e){var n,r,o=i(this);if(n=o[t])for(var s=0;sa;a++)s[a]=e(t[a]);return n.all(s,i).then(function(e){for(var i=new Array(o),n=0,r=0;o>r;r++)e[r]&&(i[n]=t[r],n++);return i.length=n,i})})}}),e("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(t,e,i,n,r){"use strict";function o(t,e,i){this._superConstructor(t,e,!1,i)}var s=t["default"],a=e.makeSettledResult,h=i["default"],c=e["default"],l=n.o_create;o.prototype=l(h.prototype),o.prototype._superConstructor=c,o.prototype._makeResult=a,o.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},r["default"]=function(t,e){return new o(s,t,e).promise}}),e("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(t,e,i,n){"use strict";{var r=t["default"],o=e["default"];i.ABORT_ON_REJECTION}n["default"]=function(t,e){return new o(r,t,e).promise}}),e("rsvp/instrument",["./config","./utils","exports"],function(t,e,i){"use strict";var n=t.config,r=e.now,o=[];i["default"]=function(t,e,i){1===o.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:r(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;ea;a++)s[a]=e(t[a]);return n.all(s,i)})}}),e("rsvp/node",["./promise","./utils","exports"],function(t,e,i){"use strict";var n=t["default"],r=e.isArray;i["default"]=function(t,e){function i(){for(var i=arguments.length,r=new Array(i),a=0;i>a;a++)r[a]=arguments[a];var h;return o||s||!e?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=e),n.all(r).then(function(i){function r(n,r){function a(){for(var t=arguments.length,i=new Array(t),a=0;t>a;a++)i[a]=arguments[a];var h=i[0],c=i[1];if(h)r(h);else if(o)n(i.slice(1));else if(s){var l,p,u={},d=i.slice(1);for(p=0;pa;a++)o=i[a],this._eachEntry(o.entry,o.position)}}),e("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(t,e,i,n,r,o,s,a,h,c,l){"use strict";function p(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function u(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(t,e){this._id=C++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),m!==t&&(v(t)||p(),this instanceof d||u(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),v=(n.objectOrFunction,n.isFunction),y=n.now,m=r.noop,w=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,S=r.invokeCallback,P=r.FULFILLED,b=o["default"],B=s["default"],U=a["default"],x=h["default"],J=c["default"],R="rsvp_"+y()+"-",C=0;l["default"]=d,d.cast=b,d.all=B,d.race=U,d.resolve=x,d.reject=J,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,i){var n=this;n._onerror=null;var r=new this.constructor(m,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===P&&t?f.async(function(){S(o,r,t,s)}):w(n,r,t,e),r},"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)}}}),e("rsvp/promise/all",["../enumerator","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return new i(this,t,!0,e).promise}}),e("rsvp/promise/cast",["./resolve","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=i}),e("rsvp/promise/race",["../utils","../-internal","exports"],function(t,e,i){"use strict";var n=t.isArray,r=(t.isFunction,t.isMaybeThenable,e.noop),o=e.resolve,s=e.reject,a=e.subscribe,h=e.PENDING;i["default"]=function(t,e){function i(t){o(p,t)}function c(t){s(p,t)}var l=this,p=new l(r,e);if(!n(t))return s(p,new TypeError("You must pass an array to race.")),p;for(var u=t.length,d=0;p._state===h&&u>d;d++)a(l.resolve(t[d]),void 0,i,c);return p}}),e("rsvp/promise/reject",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.reject;e["default"]=function(t,e){var r=this,o=new r(i,e);return n(o,t),o}}),e("rsvp/promise/resolve",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.resolve;e["default"]=function(t,e){var r=this;if(t&&"object"==typeof t&&t.constructor===r)return t;var o=new r(i,e);return n(o,t),o}}),e("rsvp/race",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.race(t,e)}}),e("rsvp/reject",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.reject(t,e)}}),e("rsvp/resolve",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.resolve(t,e)}}),e("rsvp/rethrow",["exports"],function(t){"use strict";t["default"]=function(t){throw setTimeout(function(){throw t}),t}}),e("rsvp/utils",["exports"],function(t){"use strict";function e(t){return"function"==typeof t||"object"==typeof t&&null!==t}function i(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}t.objectOrFunction=e,t.isFunction=i,t.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var o=r;t.isArray=o;var s=Date.now||function(){return(new Date).getTime()};t.now=s;var a=Object.create||function(t){var e=function(){};return e.prototype=t,e};t.o_create=a}),e("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(t,e,i,n,r,o,s,a,h,c,l,p,u,d,f,g,v){"use strict";function y(t,e){k.async(t,e)}function m(){k.on.apply(k,arguments)}function w(){k.off.apply(k,arguments)}var E=t["default"],S=e["default"],P=i["default"],b=n["default"],B=r["default"],U=o["default"],x=s["default"],J=a["default"],R=h["default"],C=c["default"],k=l.config,_=l.configure,T=p["default"],F=u["default"],I=d["default"],N=f["default"],V=g["default"];if(k.async=V,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var A=window.__PROMISE_INSTRUMENTATION__;_("instrument",!0);for(var O in A)A.hasOwnProperty(O)&&m(O,A[O])}v.Promise=E,v.EventTarget=S,v.all=b,v.allSettled=B,v.race=U,v.hash=x,v.hashSettled=J,v.rethrow=R,v.defer=C,v.denodeify=P,v.configure=_,v.on=m,v.off=w,v.resolve=F,v.reject=I,v.async=y,v.map=T,v.filter=N}),t.RSVP=i("rsvp")}(self),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,l=XMLHttpRequest.prototype;"overrideMimeType"in l||Object.defineProperty(l,"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,l={},p=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}:(l.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]||"")?(l.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),l.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),l.steps=[],a.forEach(function(t){var e;t&&(e=p(t),l.steps.push(e))}),c=parseInt(h),isNaN(c)||l.steps.push(c%2===0?p(h):{type:"text",index:(c-1)/2}),o=r.match(/\[(.*)\]/),o&&o[1]?(l.characterOffset=parseInt(r.split("[")[0]),l.textLocationAssertion=o[1]):l.characterOffset=parseInt(r),l):{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){this.container=t,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.tolerance=100,this.prevScrollTop=0,this.prevScrollLeft=0,t&&this.start()},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.ignore?(scrollTop=this.container.scrollTop,scrollLeft=this.container.scrollLeft,this.trigger("scroll",{top:scrollTop,left:scrollLeft}),scrollTop-this.prevScrollTop>this.tolerance&&this.forwards(),scrollTop-this.prevScrollTop<-this.tolerance&&this.backwards(),scrollLeft-this.prevScrollLeft>this.tolerance&&this.forwards(),scrollLeft-this.prevScrollLeft<-this.tolerance&&this.backwards(),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,this.scrolled=!1):(this.ignore=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!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(t){this.view=t,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),l=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=h+l,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]=l+"px",this.colWidth=h,this.gap=l,{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(t){this.view=t,this.documentElement=t.document.documentElement,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,i){var n=EPUBJS.core.prefixed("columnAxis"),r=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),s=EPUBJS.core.prefixed("columnFill"),a=2,h=Math.floor(t),c=h%2===0?h:h-1,l=Math.floor(c/8),p=i>=0?i:l%2===0?l:l-1,u=Math.floor((c-p)/a);return this.spreadWidth=(u+p)*a,this.view.document.documentElement.style.overflow="hidden",this.view.document.body.style.width=c+"px",this.view.document.body.style.height=e+"px",this.view.document.body.style[n]="horizontal",this.view.document.body.style[s]="auto",this.view.document.body.style[r]=p+"px",this.view.document.body.style[o]=u+"px",this.colWidth=u,this.gap=p,this.view.document.body.style.paddingRight=p+"px",{pageWidth:this.spreadWidth,pageHeight:e}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth);return{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"),l=c.getAttribute("src"),p=a.querySelector("navLabel"),u=p.textContent?p.textContent:"",d=l.split("#"),f=(d[0],e(a));n.unshift({id:h,href:l,label:u,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)),void this.hooks.display.register(this.afterDisplay.bind(this))):void console.error("Not an Element")},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,e.then("vertical"===this.settings.axis?this.fillVertical.bind(this):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.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();i.bottom>=n.top-this.settings.offset&&!(i.top>n.bottom)&&i.right>=n.left&&!(i.left>n.right+this.settings.offset)?t.shown||this.rendering||(console.log("render",t.index),this.render(t)):t.shown&&(t.destroy(),console.log("destroy:",t.section.index))},EPUBJS.Rendition.prototype.check=function(){var t=this.container.getBoundingClientRect();this.views.forEach(function(e){this.isVisible(e,t)}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.trim()}.bind(this),250)},EPUBJS.Rendition.prototype.trim=function(){for(var t=!0,e=0;e0?this.views[e-1].shown:!1,r=e+1=0;r--)if(t=this.views[r],e=t.bounds().top,e-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.style.height=0,this.element.style.width=0,this.element.style.overflow="hidden",this.shown=!1,this.rendered=!1,this.observe=!1 +},EPUBJS.View.prototype.create=function(t,e){return this.iframe?this.iframe:(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.rendered=!0,this.iframe)},EPUBJS.View.prototype.resize=function(t,e){t&&this.iframe&&(this.iframe.style.width=t+"px",this.element.style.width=t+"px"),e&&this.iframe&&(this.iframe.style.height=e+"px",this.element.style.height=e+"px"),this.resizing||(this.resizing=!0,this.iframe&&this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.iframe},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(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(){}.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||1,c=10*e;return this.resizing=!0,i=this.document.body.getBoundingClientRect(),!i||0===i.height&&0===i.width?(console.error("View not shown"),s):(r=i.height,n=this.document.documentElement.scrollWidth,a>=h&&(this.width!=n||this.height!=r)?setTimeout(function(){h+=1,this.expand(o,h)}.bind(this),c):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.element.style.width=this.width+"px",this.element.style.height=this.height+"px",this.iframe.style.display="inline-block",this.iframe.style.visibility="visible",this.trigger("shown",this),this.shown=!0},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.trigger("hidden")},EPUBJS.View.prototype.position=function(){return this.element.getBoundingClientRect()},EPUBJS.View.prototype.bounds=function(){var t=this.element.getBoundingClientRect(),e=window.getComputedStyle(this.element),i=parseInt(e.marginTop)+parseInt(e.marginBottom)||0,n=parseInt(e.marginLeft)+parseInt(e.marginLeft)||0,r=parseInt(e.borderTop)+parseInt(e.borderBottom)||0,o=parseInt(e.borderLeft)+parseInt(e.borderRight)||0;return{height:t.height+i+r,width:t.width+n+o}},EPUBJS.View.prototype.destroy=function(){this.iframe&&(this.element.removeChild(this.iframe),this.shown=!1,this.iframe=null)},RSVP.EventTarget.mixin(EPUBJS.View.prototype),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/pages.html b/examples/pages.html index df443b0..e0380a3 100644 --- a/examples/pages.html +++ b/examples/pages.html @@ -113,7 +113,8 @@