diff --git a/dist/epub.js b/dist/epub.js index 2722e1f..3827860 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -2242,7 +2242,7 @@ EPUBJS.Queue.prototype.dequeue = function(){ inwait.deferred.resolve.apply(this.context, arguments); }.bind(this)); } else { - // Task is resolves immediately + // Task resolves immediately inwait.deferred.resolve.apply(this.context, result); return inwait.promise; } @@ -2350,21 +2350,31 @@ EPUBJS.Hook.prototype.register = function(func){ // Triggers a hook to run all functions EPUBJS.Hook.prototype.trigger = function(){ - var length = this.hooks.length; + var hooks = this.hooks; + var length = hooks.length; var current = 0; var executing; var defer = new RSVP.defer(); var args = arguments; - + var next = function(){ + current += 1; + if(current < length) { + return hooks[current].apply(this.context, args); + } + }.bind(this); if(length) { executing = this.hooks[current].apply(this.context, args); - executing.then(function(){ - current += 1; - if(current < length) { - return this.hooks[current].apply(this.context, args); - } - }.bind(this)); + + if(executing && typeof executing["then"] === "function") { + // Task is a function that returns a promise + executing.then(next); + } else { + // Task resolves immediately + next(); + } + + } else { executing = defer.promise; @@ -4027,7 +4037,7 @@ EPUBJS.View.prototype.contentWidth = function(min) { // Save previous width prev = this.iframe.style.width; // Set the iframe size to min, width will only ever be greater - this.iframe.style.width = (min || 0) + "px"; + this.iframe.style.width = 0 + "px"; // Get the scroll overflow width width = this.document.body.scrollWidth; // Reset iframe size back @@ -4254,7 +4264,7 @@ EPUBJS.View.prototype.mediaQueryListeners = function() { for (var i = 0; i < sheets.length; i += 1) { var rules = sheets[i].cssRules; - + if(!rules) return; // Stylesheets changed for (var j = 0; j < rules.length; j += 1) { //if (rules[j].constructor === CSSMediaRule) { if(rules[j].media){ @@ -4424,6 +4434,64 @@ EPUBJS.View.prototype.locationOf = function(target) { return {"left": 0, "top": 0}; }; +EPUBJS.View.prototype.addCss = function(src) { + var $stylesheet = document.createElement('link'); + var ready = false; + + return new RSVP.Promise(function(resolve, reject){ + if(!this.document) { + resolve(false); + return; + } + + $stylesheet.type = 'text/css'; + $stylesheet.rel = "stylesheet"; + $stylesheet.href = src; + $stylesheet.onload = $stylesheet.onreadystatechange = function() { + if ( !ready && (!this.readyState || this.readyState == 'complete') ) { + ready = true; + // Let apply + setTimeout(function(){ + resolve(true); + }, 1); + } + }; + + this.document.head.appendChild($stylesheet); + + }.bind(this)); +}; + +// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule +EPUBJS.View.prototype.addStylesheetRules = function(rules) { + var styleEl = document.createElement('style'), + styleSheet; + + if(!this.document) return; + + // Append style element to head + this.document.head.appendChild(styleEl); + + // Grab style sheet + styleSheet = styleEl.sheet; + + for (var i = 0, rl = rules.length; i < rl; i++) { + var j = 1, rule = rules[i], selector = rules[i][0], propStr = ''; + // If the second argument of a rule is an array of arrays, correct our variables. + if (Object.prototype.toString.call(rule[1][0]) === '[object Array]') { + rule = rule[1]; + j = 0; + } + + for (var pl = rule.length; j < pl; j++) { + var prop = rule[j]; + propStr += prop[0] + ':' + prop[1] + (prop[2] ? ' !important' : '') + ';\n'; + } + + // Insert CSS Rule + styleSheet.insertRule(selector + '{' + propStr + '}', styleSheet.cssRules.length); + } +}; RSVP.EventTarget.mixin(EPUBJS.View.prototype); EPUBJS.Layout = EPUBJS.Layout || {}; @@ -4608,6 +4676,7 @@ EPUBJS.Rendition = function(book, options) { this.hooks.replacements = new EPUBJS.Hook(this); this.hooks.replacements.register(EPUBJS.replace.links.bind(this)); + // this.hooks.display.register(this.afterDisplay.bind(this)); this.epubcfi = new EPUBJS.EpubCFI(); @@ -4716,7 +4785,7 @@ EPUBJS.Rendition.prototype.attachTo = function(_element){ this.stageSize(); // Add Layout method - this.layoutMethod(); + this.applyLayoutMethod(); // Trigger Attached this.trigger("attached"); @@ -4955,15 +5024,15 @@ EPUBJS.Rendition.prototype.stageSize = function(_width, _height){ }; -EPUBJS.Rendition.prototype.layoutMethod = function() { +EPUBJS.Rendition.prototype.applyLayoutMethod = function() { this.layout = new EPUBJS.Layout.Scroll(); - this.layoutUpdate(); + this.updateLayout(); this.map = new EPUBJS.Map(this.layout); }; -EPUBJS.Rendition.prototype.layoutUpdate = function() { +EPUBJS.Rendition.prototype.updateLayout = function() { this.layout.calculate(this.stage.width, this.stage.height); @@ -4973,7 +5042,7 @@ EPUBJS.Rendition.prototype.resize = function(width, height){ this.stageSize(width, height); - this.layoutUpdate(); + this.updateLayout(); this.views.forEach(this.resizeView.bind(this)); @@ -5817,7 +5886,7 @@ EPUBJS.Paginate = function(book, options) { EPUBJS.core.extend(this.settings, options); - this.isForcedSingle = false; + this.isForcedSingle = this.settings.forceSingle; this.viewSettings = { axis: this.settings.axis @@ -5839,13 +5908,14 @@ EPUBJS.Paginate.prototype.determineSpreads = function(cutoff){ }; EPUBJS.Paginate.prototype.forceSingle = function(bool){ - if(bool) { - this.isForcedSingle = true; + if(bool === false) { + this.isForcedSingle = false; // this.spreads = false; } else { - this.isForcedSingle = false; + this.isForcedSingle = true; // this.spreads = this.determineSpreads(this.minSpreadWidth); } + this.applyLayoutMethod(); }; /** @@ -5854,35 +5924,35 @@ EPUBJS.Paginate.prototype.forceSingle = function(bool){ * Takes: Layout settings object * Returns: String of appropriate for EPUBJS.Layout function */ -EPUBJS.Paginate.prototype.determineLayout = function(settings){ - // Default is layout: reflowable & spread: auto - var spreads = this.determineSpreads(this.settings.minSpreadWidth); - console.log("spreads", spreads, this.settings.minSpreadWidth) - var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable"; - var scroll = false; - - if(settings.layout === "pre-paginated") { - layoutMethod = "Fixed"; - scroll = true; - spreads = false; - } - - if(settings.layout === "reflowable" && settings.spread === "none") { - layoutMethod = "Reflowable"; - scroll = false; - spreads = false; - } - - if(settings.layout === "reflowable" && settings.spread === "both") { - layoutMethod = "ReflowableSpreads"; - scroll = false; - spreads = true; - } - - this.spreads = spreads; - - return layoutMethod; -}; +// EPUBJS.Paginate.prototype.determineLayout = function(settings){ +// // Default is layout: reflowable & spread: auto +// var spreads = this.determineSpreads(this.settings.minSpreadWidth); +// console.log("spreads", spreads, this.settings.minSpreadWidth) +// var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable"; +// var scroll = false; +// +// if(settings.layout === "pre-paginated") { +// layoutMethod = "Fixed"; +// scroll = true; +// spreads = false; +// } +// +// if(settings.layout === "reflowable" && settings.spread === "none") { +// layoutMethod = "Reflowable"; +// scroll = false; +// spreads = false; +// } +// +// if(settings.layout === "reflowable" && settings.spread === "both") { +// layoutMethod = "ReflowableSpreads"; +// scroll = false; +// spreads = true; +// } +// +// this.spreads = spreads; +// +// return layoutMethod; +// }; EPUBJS.Paginate.prototype.start = function(){ // On display @@ -5891,6 +5961,7 @@ EPUBJS.Paginate.prototype.start = function(){ // this.layout = new EPUBJS.Layout[this.layoutMethod](); //this.hooks.display.register(this.registerLayoutMethod.bind(this)); this.hooks.display.register(this.reportLocation); + this.hooks.replacements.register(this.adjustImages.bind(this)); this.currentPage = 0; @@ -5908,14 +5979,14 @@ EPUBJS.Paginate.prototype.start = function(){ // return view; // }; -EPUBJS.Paginate.prototype.layoutMethod = function() { +EPUBJS.Paginate.prototype.applyLayoutMethod = function() { //var task = new RSVP.defer(); // this.spreads = this.determineSpreads(this.settings.minSpreadWidth); this.layout = new EPUBJS.Layout.Reflowable(); - this.layoutUpdate(); + this.updateLayout(); // Set the look ahead offset for what is visible @@ -5928,7 +5999,7 @@ EPUBJS.Paginate.prototype.layoutMethod = function() { // return layout; }; -EPUBJS.Paginate.prototype.layoutUpdate = function() { +EPUBJS.Paginate.prototype.updateLayout = function() { this.spreads = this.determineSpreads(this.settings.minSpreadWidth); @@ -6026,7 +6097,7 @@ EPUBJS.Paginate.prototype.resize = function(width, height){ this.stageSize(width, height); - this.layoutUpdate(); + this.updateLayout(); this.display(this.location.start); @@ -6047,6 +6118,22 @@ EPUBJS.Paginate.prototype.onResized = function(e) { }.bind(this), 150); }; +EPUBJS.Paginate.prototype.adjustImages = function(view) { + + view.addStylesheetRules([ + ["img", + ["max-width", (this.layout.spread) + "px"], + ["max-height", (this.layout.height) + "px"] + ] + ]); + return new RSVP.Promise(function(resolve, reject){ + // Wait to apply + setTimeout(function() { + resolve(); + }, 1); + }); +}; + // EPUBJS.Paginate.prototype.display = function(what){ // return this.display(what); // }; diff --git a/dist/epub.min.js b/dist/epub.min.js index 4331381..82e7a42 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(){"use strict";function t(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function e(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}function i(t,e){return"onerror"===t?(Y.on("error",e),void 0):2!==arguments.length?Y[t]:(Y[t]=e,void 0)}function n(t){return"function"==typeof t||"object"==typeof t&&null!==t}function r(t){return"function"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(){}function a(){}function h(t){try{return t.then}catch(e){return oe.error=e,oe}}function u(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function c(t,e,i){Y.async(function(t){var n=!1,r=u(i,e,function(i){n||(n=!0,e!==i?d(t,i):g(t,i))},function(e){n||(n=!0,y(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,y(t,r))},t)}function l(t,e){e._state===ne?g(t,e._result):t._state===re?y(t,e._result):m(e,void 0,function(i){e!==i?d(t,i):g(t,i)},function(e){y(t,e)})}function p(t,e){if(e.constructor===t.constructor)l(t,e);else{var i=h(e);i===oe?y(t,oe.error):void 0===i?g(t,e):r(i)?c(t,e,i):g(t,e)}}function d(t,e){t===e?g(t,e):n(e)?p(t,e):g(t,e)}function f(t){t._onerror&&t._onerror(t._result),S(t)}function g(t,e){t._state===ie&&(t._result=e,t._state=ne,0===t._subscribers.length?Y.instrument&&ee("fulfilled",t):Y.async(S,t))}function y(t,e){t._state===ie&&(t._state=re,t._result=e,Y.async(f,t))}function m(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+ne]=i,r[o+re]=n,0===o&&t._state&&Y.async(S,t)}function S(t){var e=t._subscribers,i=t._state;if(Y.instrument&&ee(i===ne?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;sa;a++)s[a]=t[a];for(n=0;nn;n++)i[n-1]=t[n];return i}function N(t,e){return{then:function(i,n){return t.call(e,i,n)}}}function q(t,e,i,n){var r=_(i,n,e);return r===ge&&y(t,r.value),t}function F(t,e,i,n){return fe.all(e).then(function(e){var r=_(i,n,e);return r===ge&&y(t,r.value),t})}function L(t){return t&&"object"==typeof t?t.constructor===fe?!0:R(t):!1}function O(t,e,i){this._superConstructor(t,e,!1,i)}function I(t,e,i){this._superConstructor(t,e,!0,i)}function V(t,e,i){this._superConstructor(t,e,!1,i)}function A(){return function(){process.nextTick(D)}}function M(){var t=0,e=new qe(D),i=document.createTextNode("");return e.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}function z(){var t=new MessageChannel;return t.port1.onmessage=D,function(){t.port2.postMessage(0)}}function H(){return function(){setTimeout(D,1)}}function D(){for(var t=0;Te>t;t+=2){var e=Le[t],i=Le[t+1];e(i),Le[t]=void 0,Le[t+1]=void 0}Te=0}function j(t,e){Y.async(t,e)}function W(){Y.on.apply(Y,arguments)}function X(){Y.off.apply(Y,arguments)}var Q={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(i,n){var r,o=e(this);r=o[i],r||(r=o[i]=[]),-1===t(r,n)&&r.push(n)},off:function(i,n){var r,o,s=e(this);return n?(r=s[i],o=t(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(t,i){var n,r,o=e(this);if(n=o[t])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof t)throw new TypeError("Argument must be an object");return s.prototype=t,new s},te=[],ee=function(t,e,i){1===te.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:Z(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;en;n++)this._eachEntry(i[n],n)},U.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;o(t)?t.constructor===i&&t._state!==ie?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(ne,e,t))},U.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===ie&&(this._remaining--,this._abortOnReject&&t===re?y(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&g(n,this._result)},U.prototype._makeResult=function(t,e,i){return i},U.prototype._willSettleAt=function(t,e){var i=this;m(t,void 0,function(t){i._settledAt(ne,e,t)},function(t){i._settledAt(re,e,t)})};var he=function(t,e){return new ae(this,t,!0,e).promise},ue=function(t,e){function i(t){d(o,t)}function n(t){y(o,t)}var r=this,o=new r(a,e);if(!G(t))return y(o,new TypeError("You must pass an array to race.")),o;for(var s=t.length,h=0;o._state===ie&&s>h;h++)m(r.resolve(t[h]),void 0,i,n);return o},ce=function(t,e){var i=this;if(t&&"object"==typeof t&&t.constructor===i)return t;var n=new i(a,e);return d(n,t),n},le=function(t,e){var i=this,n=new i(a,e);return y(n,t),n},pe="rsvp_"+Z()+"-",de=0,fe=x;x.cast=ce,x.all=he,x.race=ue,x.resolve=ce,x.reject=le,x.prototype={constructor:x,_guidKey:pe,_onerror:function(t){Y.trigger("error",t)},then:function(t,e,i){var n=this,r=n._state;if(r===ne&&!t||r===re&&!e)return Y.instrument&&ee("chained",this,this),this;n._onerror=null;var o=new this.constructor(a,i),s=n._result;if(Y.instrument&&ee("chained",n,o),r){var h=arguments[r-1];Y.async(function(){P(r,o,h,s)})}else m(n,o,t,e);return o},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}};var ge=new C,ye=new C,me=function(t,e){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,h=0;r>h;++h){if(i=arguments[h],!s){if(s=L(i),s===ye){var u=new fe(a);return y(u,ye.value),u}s&&s!==!0&&(i=N(s,i))}o[h]=i}var c=new fe(a);return o[r]=function(t,i){t?y(c,t):void 0===e?d(c,i):e===!0?d(c,k(arguments)):G(e)?d(c,T(arguments,e)):d(c,i)},s?F(c,o,t,n):q(c,o,t,n)};return i.__proto__=t,i},Se=function(t,e){return fe.all(t,e)};O.prototype=$(ae.prototype),O.prototype._superConstructor=ae,O.prototype._makeResult=w,O.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var ve=function(t,e){return new O(fe,t,e).promise},Ee=function(t,e){return fe.race(t,e)},Pe=I;I.prototype=$(ae.prototype),I.prototype._superConstructor=ae,I.prototype._init=function(){this._result={}},I.prototype._validateInput=function(t){return t&&"object"==typeof t},I.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},I.prototype._enumerate=function(){var t=this.promise,e=this._input,i=[];for(var n in e)t._state===ie&&e.hasOwnProperty(n)&&i.push({position:n,entry:e[n]});var r=i.length;this._remaining=r;for(var o,s=0;t._state===ie&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var Be=function(t,e){return new Pe(fe,t,e).promise};V.prototype=$(Pe.prototype),V.prototype._superConstructor=ae,V.prototype._makeResult=w,V.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var we,Ue=function(t,e){return new V(fe,t,e).promise},be=function(t){throw setTimeout(function(){throw t}),t},Je=function(t){var e={};return e.promise=new fe(function(t,i){e.resolve=t,e.reject=i},t),e},xe=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as map's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i)})},Ce=function(t,e){return fe.resolve(t,e)},Re=function(t,e){return fe.reject(t,e)},_e=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as filter's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i).then(function(e){for(var i=new Array(n),r=0,o=0;n>o;o++)e[o]&&(i[r]=t[o],r++);return i.length=r,i})})},Te=0,ke=function(t,e){Le[Te]=t,Le[Te+1]=e,Te+=2,2===Te&&we()},Ne="undefined"!=typeof window?window:{},qe=Ne.MutationObserver||Ne.WebKitMutationObserver,Fe="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Le=new Array(1e3);we="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?A():qe?M():Fe?z():H(),Y.async=ke;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Oe=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Ie in Oe)Oe.hasOwnProperty(Ie)&&W(Ie,Oe[Ie])}var Ve={race:Ee,Promise:fe,allSettled:ve,hash:Be,hashSettled:Ue,denodeify:me,on:W,off:X,map:xe,filter:_e,resolve:Ce,reject:Re,all:Se,rethrow:be,defer:Je,EventTarget:Q,configure:i,async:j};"function"==typeof define&&define.amd?define(function(){return Ve}):"undefined"!=typeof module&&module.exports?module.exports=Ve:"undefined"!=typeof this&&(this.RSVP=Ve)}.call(this),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,u=new XMLHttpRequest,c=XMLHttpRequest.prototype;"overrideMimeType"in c||Object.defineProperty(c,"overrideMimeType",{value:function(){}}),i&&(u.withCredentials=!0),u.open("GET",t,!0);for(o in n)u.setRequestHeader(o,n[o]);return u.onreadystatechange=r,"blob"==e&&(u.responseType=a),"json"==e&&u.setRequestHeader("Accept","application/json"),"xml"==e&&u.overrideMimeType("text/xml"),u.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.extend=function(t){var e=[].slice.call(arguments,1);return e.forEach(function(e){e&&Object.getOwnPropertyNames(e).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(e,i))})}),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.core.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,EPUBJS.core.bounds=function(t){var e=window.getComputedStyle(t),i=["width","paddingRight","paddingLeft","marginRight","marginLeft","borderRightWidth","borderLeftWidth"],n=["height","paddingTop","paddingBottom","marginTop","marginBottom","borderTopWidth","borderBottomWidth"],r=0,o=0;return i.forEach(function(t){r+=parseFloat(e[t])||0}),n.forEach(function(t){o+=parseFloat(e[t])||0}),{height:o,width:r}},EPUBJS.core.borders=function(t){var e=window.getComputedStyle(t),i=["paddingRight","paddingLeft","marginRight","marginLeft","borderRightWidth","borderLeftWidth"],n=["paddingTop","paddingBottom","marginTop","marginBottom","borderTopWidth","borderBottomWidth"],r=0,o=0;return i.forEach(function(t){r+=parseFloat(e[t])||0}),n.forEach(function(t){o+=parseFloat(e[t])||0}),{height:o,width:r}},EPUBJS.core.windowBounds=function(){var t=window.innerWidth,e=window.innerHeight;return{top:0,left:0,right:t,bottom:e,width:t,height:e}},EPUBJS.core.cleanStringForXpath=function(t){var e=t.match(/[^'"]+|['"]/g);return e=e.map(function(t){return"'"===t?'"\'"':'"'===t?"'\"'":"'"+t+"'"}),"concat('',"+e.join(",")+")"},EPUBJS.core.indexOfTextNode=function(t){for(var e,i=t.parentNode,n=i.childNodes,r=-1,o=0;oi?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(t=n.promise,n.resolve()),t},EPUBJS.Parser=function(){},EPUBJS.Parser.prototype.container=function(t){var e,i,n,r;return t?(e=t.querySelector("rootfile"))?(i=e.getAttribute("full-path"),n=EPUBJS.core.uri(i).directory,r=t.xmlEncoding,{packagePath:i,basePath:n,encoding:r}):(console.error("No RootFile Found"),void 0):(console.error("Container File Not Found"),void 0)},EPUBJS.Parser.prototype.identifier=function(t){var e;return t?(e=t.querySelector("metadata"),e?this.getElementText(e,"identifier"):(console.error("No Metadata Found"),void 0)):(console.error("Package File Not Found"),void 0)},EPUBJS.Parser.prototype.packageContents=function(t){var e,i,n,r,o,s,a,h,u,c=this;return t?(e=t.querySelector("metadata"))?(i=t.querySelector("manifest"))?(n=t.querySelector("spine"))?(r=c.manifest(i),o=c.findNavPath(i),s=c.findNcxPath(i),a=c.findCoverPath(i),h=Array.prototype.indexOf.call(n.parentNode.childNodes,n),u=c.spine(n,r),{metadata:c.metadata(e),spine:u,manifest:r,navPath:o,ncxPath:s,coverPath:a,spineNodeIndex:h}):(console.error("No Spine Found"),void 0):(console.error("No Manifest Found"),void 0):(console.error("No Metadata Found"),void 0):(console.error("Package File Not Found"),void 0)},EPUBJS.Parser.prototype.findNavPath=function(t){var e=t.querySelector("item[properties^='nav']");return e?e.getAttribute("href"):!1},EPUBJS.Parser.prototype.findNcxPath=function(t){var e=t.querySelector("item[media-type='application/x-dtbncx+xml']");return e?e.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(t){var e=t.querySelector("item[properties='cover-image']");return e?e.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(t){var e={},i=this;return e.title=i.getElementText(t,"title"),e.creator=i.getElementText(t,"creator"),e.description=i.getElementText(t,"description"),e.pubdate=i.getElementText(t,"date"),e.publisher=i.getElementText(t,"publisher"),e.identifier=i.getElementText(t,"identifier"),e.language=i.getElementText(t,"language"),e.rights=i.getElementText(t,"rights"),e.modified_date=i.querySelectorText(t,"meta[property='dcterms:modified']"),e.layout=i.querySelectorText(t,"meta[property='rendition:layout']"),e.orientation=i.querySelectorText(t,"meta[property='rendition:orientation']"),e.spread=i.querySelectorText(t,"meta[property='rendition:spread']"),e},EPUBJS.Parser.prototype.getElementText=function(t,e){var i,n=t.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",e);return n&&0!==n.length?(i=n[0],i.childNodes.length?i.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(t,e){var i=t.querySelector(e);return i&&i.childNodes.length?i.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(t){var e={},i=t.querySelectorAll("item"),n=Array.prototype.slice.call(i);return n.forEach(function(t){var i=t.getAttribute("id"),n=t.getAttribute("href")||"",r=t.getAttribute("media-type")||"",o=t.getAttribute("properties")||"";e[i]={href:n,type:r,properties:o.length?o.split(" "):[]}}),e},EPUBJS.Parser.prototype.spine=function(t){{var e=[],i=t.getElementsByTagName("itemref"),n=Array.prototype.slice.call(i);new EPUBJS.EpubCFI}return n.forEach(function(t,i){var n=t.getAttribute("idref"),r=t.getAttribute("properties")||"",o=r.length?r.split(" "):[],s={idref:n,linear:t.getAttribute("linear")||"",properties:o,index:i};e.push(s)}),e},EPUBJS.Parser.prototype.nav=function(t){function e(t){var e=[];return Array.prototype.slice.call(t.childNodes).forEach(function(t){"ol"==t.tagName&&Array.prototype.slice.call(t.childNodes).forEach(function(t){"li"==t.tagName&&e.push(t)})}),e}function i(t){var e=null;return Array.prototype.slice.call(t.childNodes).forEach(function(t){("a"==t.tagName||"span"==t.tagName)&&(e=t)}),e}function n(t){var r=[],o=e(t),s=Array.prototype.slice.call(o),a=s.length;return 0===a?!1:(s.forEach(function(e){var o=e.getAttribute("id")||!1,s=i(e),a=s.getAttribute("href")||"",h=s.textContent||"",u=a.split("#"),c=(u[0],n(e));r.push({id:o,href:a,label:h,subitems:c,parent:t?t.getAttribute("id"):null})}),r)}var r=t.querySelector('nav[*|type="toc"]');return r?n(r):[]},EPUBJS.Parser.prototype.ncx=function(t){function e(i){var n=[],r=t.evaluate("*[local-name()='navPoint']",i,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),o=r.snapshotLength;if(0===o)return[];for(var s=o-1;s>=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,u=a.querySelector("content"),c=u.getAttribute("src"),l=a.querySelector("navLabel"),p=l.textContent?l.textContent:"",d=c.split("#"),f=(d[0],e(a));n.unshift({id:h,href:c,label:p,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},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,u,c={},l=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(c.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]||"")?(c.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),c.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),c.steps=[],a.forEach(function(t){var e;t&&(e=l(t),c.steps.push(e))}),u=parseInt(h),isNaN(u)||(u%2===0?c.steps.push(l(h)):c.steps.push({type:"text",index:(u-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(c.characterOffset=parseInt(r.split("[")[0]),c.textLocationAssertion=o[1]):c.characterOffset=parseInt(r),c):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(t,e,i){var n,r,o,s,a=e||document,h=i||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,t.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffset-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.replace={},EPUBJS.replace.links=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-1&&(this.observer=this.observe(this.document.body)),this.imageLoadListeners(),this.mediaQueryListeners(),this.resizeListenters()},EPUBJS.View.prototype.resizeListenters=function(){clearTimeout(this.expanding),this.expanding=setTimeout(this.expand.bind(this),350)},EPUBJS.View.prototype.mediaQueryListeners=function(){for(var t=this.document.styleSheets,e=function(t){t.matches&&this.expand()}.bind(this),i=0;i-1&&(id=t.substring(t.indexOf("#")),el=this.document.getElementById(id)))return el.getBoundingClientRect();return{left:0,top:0}}},RSVP.EventTarget.mixin(EPUBJS.View.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){},EPUBJS.Layout.Reflowable.prototype.calculate=function(t,e,i,n){var r,o,s,a=n||1,h=Math.floor(t),u=h%2===0?h:h-1,c=Math.floor(u/8),l=i>=0?i:c%2===0?c:c-1;r=a>1?Math.floor((u-l)/a):u,o=r*a,s=(r+l)*a,this.columnAxis=EPUBJS.core.prefixed("columnAxis"),this.columnGap=EPUBJS.core.prefixed("columnGap"),this.columnWidth=EPUBJS.core.prefixed("columnWidth"),this.columnFill=EPUBJS.core.prefixed("columnFill"),this.width=u,this.height=e,this.spread=o,this.delta=s,this.column=r,this.gap=l,this.divisor=a},EPUBJS.Layout.Reflowable.prototype.format=function(t){var e=t.document.documentElement,i=t.document.body;e.style.overflow="hidden",e.style.width=this.width+"px",i.style.height=this.height+"px",i.style[this.columnAxis]="horizontal",i.style[this.columnFill]="auto",i.style[this.columnGap]=this.gap+"px",i.style[this.columnWidth]=this.column+"px",t.iframe.style.marginRight=this.gap+"px"},EPUBJS.Layout.Reflowable.prototype.count=function(t){var e=t.root().scrollWidth,i=Math.ceil(e/this.spread);return{spreads:i,pages:i*this.divisor}},EPUBJS.Layout.Fixed=function(){},EPUBJS.Layout.Fixed.prototype.calculate=function(){},EPUBJS.Layout.Fixed.prototype.format=function(t){var e,i,n=t.document.documentElement,r=documentElement.querySelector("[name=viewport");r&&r.hasAttribute("content")&&(content=r.getAttribute("content"),contents=content.split(","),contents[0]&&(e=contents[0].replace("width=","")),contents[1]&&(i=contents[1].replace("height=",""))),t.resize(e,i),n.style.overflow="auto"},EPUBJS.Layout.Fixed.prototype.count=function(){return{spreads:1,pages:1}},EPUBJS.Layout.Scroll=function(){},EPUBJS.Layout.Scroll.prototype.calculate=function(t){this.spread=t,this.column=t,this.gap=0},EPUBJS.Layout.Scroll.prototype.format=function(t){var e=t.document.documentElement;e.style.width="auto",e.style.height="auto"},EPUBJS.Layout.Scroll.prototype.count=function(){return{spreads:1,pages:1}},EPUBJS.Rendition=function(t,e){this.settings=EPUBJS.core.extend(this.settings||{},{infinite:!0,hidden:!1,width:!1,height:null,layoutOveride:null,axis:"vertical"}),EPUBJS.core.extend(this.settings,e),this.viewSettings={},this.book=t,this.views=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.layout=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(EPUBJS.replace.links.bind(this)),this.epubcfi=new EPUBJS.EpubCFI,this.q=new EPUBJS.Queue(this),this.q.enqueue(this.book.opened),this.q.enqueue(this.parseLayoutProperties)},EPUBJS.Rendition.prototype.initialize=function(t){{var e,i=t||{},n=i.height,r=i.width;i.hidden||!1}return i.height&&EPUBJS.core.isNumber(i.height)&&(n=i.height+"px"),i.width&&EPUBJS.core.isNumber(i.width)&&(r=i.width+"px"),e=document.createElement("div"),e.id="epubjs-container:"+EPUBJS.core.uuid(),e.classList.add("epub-container"),e.style.fontSize="0",e.style.wordSpacing="0",e.style.lineHeight="0",e.style.verticalAlign="top","horizontal"===this.settings.axis&&(e.style.whiteSpace="nowrap"),r&&(e.style.width=r),n&&(e.style.height=n),e.style.overflow=this.settings.overflow,e},EPUBJS.Rendition.wrap=function(t){var e=document.createElement("div");return e.style.visibility="hidden",e.style.overflow="hidden",e.style.width="0",e.style.height="0",e.appendChild(t),e},EPUBJS.Rendition.prototype.attachTo=function(t){return this.container=this.initialize({width:this.settings.width,height:this.settings.height}),EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.settings.hidden?(this.wrapper=this.wrap(this.container),this.element.appendChild(this.wrapper)):this.element.appendChild(this.container),this.attachListeners(),this.stageSize(),this.layoutMethod(),this.trigger("attached"),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Rendition.prototype.attachListeners=function(){EPUBJS.core.isNumber(this.settings.width)&&EPUBJS.core.isNumber(this.settings.height)||window.addEventListener("resize",this.onResized.bind(this),!1)},EPUBJS.Rendition.prototype.bounds=function(){return this.container.getBoundingClientRect()},EPUBJS.Rendition.prototype.display=function(t){return this.q.enqueue(this._display,t)},EPUBJS.Rendition.prototype._display=function(t){var e,i,n,r,o=new RSVP.defer,s=o.promise;return this.epubcfi.isCfiString(t)?(n=this.epubcfi.parse(t),r=n.spinePos,e=this.book.spine.get(r)):e=this.book.spine.get(t),this.displaying=!0,this.hide(),e?(i=this.createView(e),this.q.enqueue(this.append,i),this.show(),this.hooks.display.trigger(i),o.resolve(this)):o.reject(new Error("No Section Found")),s},EPUBJS.Rendition.prototype.moveTo=function(){},EPUBJS.Rendition.prototype.render=function(t,e){return t.create(),t.onLayout=this.layout.format.bind(this.layout),this.resizeView(t),t.render(this.book.request).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return this.hooks.layout.trigger(t)}.bind(this)).then(function(){return t.display()}.bind(this)).then(function(t){0!=e&&this.hidden===!1&&this.q.enqueue(function(t){t.show()},t),this.trigger("rendered",t.section)}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Rendition.prototype.afterDisplayed=function(t){this.trigger("displayed",t.section)},EPUBJS.Rendition.prototype.append=function(t){return this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=this.afterDisplayed.bind(this),this.render(t)},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){this._remove(t)}.bind(this)),this.views=[]},EPUBJS.Rendition.prototype.remove=function(t){var e=this.views.indexOf(t);e>-1&&this.views.splice(e,1),this._remove(t)},EPUBJS.Rendition.prototype._remove=function(t){t.off("resized"),t.displayed&&t.destroy(),this.container.removeChild(t.element),t=null},EPUBJS.Rendition.prototype.resizeView=function(t){"pre-paginated"===this.globalLayoutProperties.layout?t.lock("both",this.stage.width,this.stage.height):t.lock("width",this.stage.width,this.stage.height)},EPUBJS.Rendition.prototype.stageSize=function(t,e){var i,n=t||this.settings.width,r=e||this.settings.height;return n===!1&&(i=this.element.getBoundingClientRect(),i.width&&(n=i.width,this.container.style.width=i.width+"px")),r===!1&&(i=i||this.element.getBoundingClientRect(),i.height&&(r=i.height,this.container.style.height=i.height+"px")),n&&!EPUBJS.core.isNumber(n)&&(i=this.container.getBoundingClientRect(),n=i.width),r&&!EPUBJS.core.isNumber(r)&&(i=i||this.container.getBoundingClientRect(),r=i.height),this.containerStyles=window.getComputedStyle(this.container),this.containerPadding={left:parseFloat(this.containerStyles["padding-left"])||0,right:parseFloat(this.containerStyles["padding-right"])||0,top:parseFloat(this.containerStyles["padding-top"])||0,bottom:parseFloat(this.containerStyles["padding-bottom"])||0},this.stage={width:n-this.containerPadding.left-this.containerPadding.right,height:r-this.containerPadding.top-this.containerPadding.bottom},this.stage},EPUBJS.Rendition.prototype.layoutMethod=function(){this.layout=new EPUBJS.Layout.Scroll,this.layoutUpdate(),this.map=new EPUBJS.Map(this.layout)},EPUBJS.Rendition.prototype.layoutUpdate=function(){this.layout.calculate(this.stage.width,this.stage.height)},EPUBJS.Rendition.prototype.resize=function(t,e){this.stageSize(t,e),this.layoutUpdate(),this.views.forEach(this.resizeView.bind(this)),this.trigger("resized",{width:this.stage.width,height:this.stage.height})},EPUBJS.Rendition.prototype.onResized=function(){this.resize()},EPUBJS.Rendition.prototype.createView=function(t){return new EPUBJS.View(t,this.viewSettings)},EPUBJS.Rendition.prototype.next=function(){return this.q.enqueue(function(){var t,e;return this.views.length?(t=this.views[0].section.next(),t?(e=this.createView(t),this.append(e)):void 0):void 0})},EPUBJS.Rendition.prototype.prev=function(){return this.q.enqueue(function(){var t,e;return this.views.length?(t=this.views[0].section.prev(),t?(e=this.createView(t),this.append(e)):void 0):void 0})},EPUBJS.Rendition.prototype.parseLayoutProperties=function(t){var e=t||this.book.package.metadata,i=this.layoutOveride&&this.layoutOveride.layout||e.layout||"reflowable",n=this.layoutOveride&&this.layoutOveride.spread||e.spread||"auto",r=this.layoutOveride&&this.layoutOveride.orientation||e.orientation||"auto";return this.globalLayoutProperties={layout:i,spread:n,orientation:r},this.globalLayoutProperties},EPUBJS.Rendition.prototype.current=function(){var t=this.visible();return t.length?t[t.length-1]:null},EPUBJS.Rendition.prototype.isVisible=function(t,e,i,n){var r=t.position(),o=n||this.container.getBoundingClientRect();return"horizontal"===this.settings.axis&&r.right>o.left-e&&!(r.left>=o.right+i)?!0:"vertical"===this.settings.axis&&r.bottom>o.top-e&&!(r.top>=o.bottom+i)?!0:!1},EPUBJS.Rendition.prototype.visible=function(){for(var t,e,i=this.bounds(),n=[],r=0;r=0;r--)if(t=this.views[r],e=t.bounds().top,ethis.settings.offsetDelta||this.scrollDeltaHorz>this.settings.offsetDelta)&&(this.q.enqueue(this.check),this.scrollDeltaVert=0,this.scrollDeltaHorz=0),this.scrollDeltaVert+=Math.abs(scrollTop-this.prevScrollTop),this.scrollDeltaHorz+=Math.abs(scrollLeft-this.prevScrollLeft),this.settings.height?(this.prevScrollTop=this.container.scrollTop,this.prevScrollLeft=this.container.scrollLeft):(this.prevScrollTop=window.scrollY,this.prevScrollLeft=window.scrollX),clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(function(){this.scrollDeltaVert=0,this.scrollDeltaHorz=0}.bind(this),150),this.scrolled=!1),this.tick.call(window,this.onScroll.bind(this))},EPUBJS.Continuous.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.settings.height?(t&&(this.container.scrollLeft+=t),e&&(this.container.scrollTop+=e)):window.scrollBy(t,e),this.scrolled=!0},EPUBJS.Continuous.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!0),this.settings.height?(this.container.scrollLeft=t,this.container.scrollTop=e):window.scrollTo(t,e),this.scrolled=!0},EPUBJS.Continuous.prototype.resizeView=function(t){"horizontal"===this.settings.axis?t.lock("height",this.stage.width,this.stage.height):t.lock("width",this.stage.width,this.stage.height)},EPUBJS.Continuous.prototype.currentLocation=function(){{var t,e,i=this.visible();this.container.getBoundingClientRect()}return 1===i.length?this.map.page(i[0]):i.length>1?(t=this.map.page(i[0]),e=this.map.page(i[i.length-1]),{start:t.start,end:e.end}):void 0},EPUBJS.Paginate=function(t,e){EPUBJS.Continuous.apply(this,arguments),this.settings=EPUBJS.core.extend(this.settings||{},{width:600,height:400,axis:"horizontal",forceSingle:!1,minSpreadWidth:800,gap:"auto",overflow:"hidden",infinite:!1}),EPUBJS.core.extend(this.settings,e),this.isForcedSingle=!1,this.viewSettings={axis:this.settings.axis},this.start()},EPUBJS.Paginate.prototype=Object.create(EPUBJS.Continuous.prototype),EPUBJS.Paginate.prototype.constructor=EPUBJS.Paginate,EPUBJS.Paginate.prototype.determineSpreads=function(t){return this.isForcedSingle||!t||this.bounds().width1?(t=a.left-s[0].position().left,i=t+this.layout.column,e=a.left+this.layout.spread-s[s.length-1].position().left,n=e+this.layout.column,r=this.map.page(s[0],t,i),o=this.map.page(s[s.length-1],e,n),{start:r.start,end:o.end}):void 0},EPUBJS.Paginate.prototype.resize=function(t,e){this.q.clear(),this.stageSize(t,e),this.layoutUpdate(),this.display(this.location.start),this.trigger("resized",{width:this.stage.width,height:this.stage.height})},EPUBJS.Paginate.prototype.onResized=function(){this.clear(),clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout(function(){this.resize()}.bind(this),150)},EPUBJS.Map=function(t){this.layout=t},EPUBJS.Map.prototype.section=function(t){var e=this.findRanges(t),i=this.rangeListToCfiList(t,e);return i},EPUBJS.Map.prototype.page=function(t,e,i){var n=t.document.body;return this.rangePairToCfiPair(t.section,{start:this.findStart(n,e,i),end:this.findEnd(n,e,i)})},EPUBJS.Map.prototype.walk=function(t,e){for(var i,n,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode:function(t){return t.data.trim().length>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},!1);(i=r.nextNode())&&!(n=e(i)););return n},EPUBJS.Map.prototype.findRanges=function(t){for(var e,i,n=[],r=this.layout.count(t),o=this.layout.column,s=this.layout.gap,a=0;a=e&&i>=n?t:r>e?t:(s=t,o.push(t),void 0)}))return this.findTextStartRange(r,e,i);return this.findTextStartRange(s,e,i)},EPUBJS.Map.prototype.findEnd=function(t,e,i){for(var n,r,o=[t],s=t;o.length;)if(n=o.shift(),r=this.walk(n,function(t){var e,n,r,a;return t.nodeType==Node.TEXT_NODE?(a=document.createRange(),a.selectNodeContents(t),r=a.getBoundingClientRect()):r=t.getBoundingClientRect(),e=r.left,n=r.right,e>i&&s?s:n>i?t:(s=t,o.push(t),void 0)}))return this.findTextEndRange(r,e,i);return this.findTextEndRange(s,e,i)},EPUBJS.Map.prototype.findTextStartRange=function(t,e){for(var i,n,r,o=this.splitTextNodeIntoRanges(t),s=0;s=e)return n;i=n}return o[0]},EPUBJS.Map.prototype.findTextEndRange=function(t,e,i){for(var n,r,o,s=this.splitTextNodeIntoRanges(t),a=0;ai&&n)return n;if(o.right>i)return r;n=r}return s[s.length-1]},EPUBJS.Map.prototype.splitTextNodeIntoRanges=function(t,e){var i,n=[],r=t.textContent||"",o=r.trim(),s=t.ownerDocument,a=e||" ";if(pos=o.indexOf(a),-1===pos||t.nodeType!=Node.TEXT_NODE)return i=s.createRange(),i.selectNodeContents(t),[i];for(i=s.createRange(),i.setStart(t,0),i.setEnd(t,pos),n.push(i),i=!1;-1!=pos;)pos=o.indexOf(a,pos+1),pos>0&&(i&&(i.setEnd(t,pos),n.push(i)),i=s.createRange(),i.setStart(t,pos+1));return i&&(i.setEnd(t,o.length),n.push(i)),n},EPUBJS.Map.prototype.rangePairToCfiPair=function(t,e){var i=e.start,n=e.end;return i.collapse(!0),n.collapse(!0),startCfi=t.cfiFromRange(i),endCfi=t.cfiFromRange(n),{start:startCfi,end:endCfi}},EPUBJS.Map.prototype.rangeListToCfiList=function(t,e){for(var i,n=[],r=0;ri;i++)if(t[i]===e)return i;return-1}function e(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}function i(t,e){return"onerror"===t?(Y.on("error",e),void 0):2!==arguments.length?Y[t]:(Y[t]=e,void 0)}function n(t){return"function"==typeof t||"object"==typeof t&&null!==t}function r(t){return"function"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(){}function a(){}function h(t){try{return t.then}catch(e){return oe.error=e,oe}}function u(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function c(t,e,i){Y.async(function(t){var n=!1,r=u(i,e,function(i){n||(n=!0,e!==i?d(t,i):g(t,i))},function(e){n||(n=!0,y(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,y(t,r))},t)}function l(t,e){e._state===ne?g(t,e._result):t._state===re?y(t,e._result):m(e,void 0,function(i){e!==i?d(t,i):g(t,i)},function(e){y(t,e)})}function p(t,e){if(e.constructor===t.constructor)l(t,e);else{var i=h(e);i===oe?y(t,oe.error):void 0===i?g(t,e):r(i)?c(t,e,i):g(t,e)}}function d(t,e){t===e?g(t,e):n(e)?p(t,e):g(t,e)}function f(t){t._onerror&&t._onerror(t._result),S(t)}function g(t,e){t._state===ie&&(t._result=e,t._state=ne,0===t._subscribers.length?Y.instrument&&ee("fulfilled",t):Y.async(S,t))}function y(t,e){t._state===ie&&(t._state=re,t._result=e,Y.async(f,t))}function m(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+ne]=i,r[o+re]=n,0===o&&t._state&&Y.async(S,t)}function S(t){var e=t._subscribers,i=t._state;if(Y.instrument&&ee(i===ne?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;sa;a++)s[a]=t[a];for(n=0;nn;n++)i[n-1]=t[n];return i}function N(t,e){return{then:function(i,n){return t.call(e,i,n)}}}function q(t,e,i,n){var r=_(i,n,e);return r===ge&&y(t,r.value),t}function L(t,e,i,n){return fe.all(e).then(function(e){var r=_(i,n,e);return r===ge&&y(t,r.value),t})}function F(t){return t&&"object"==typeof t?t.constructor===fe?!0:R(t):!1}function O(t,e,i){this._superConstructor(t,e,!1,i)}function V(t,e,i){this._superConstructor(t,e,!0,i)}function I(t,e,i){this._superConstructor(t,e,!1,i)}function A(){return function(){process.nextTick(H)}}function M(){var t=0,e=new qe(H),i=document.createTextNode("");return e.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}function j(){var t=new MessageChannel;return t.port1.onmessage=H,function(){t.port2.postMessage(0)}}function z(){return function(){setTimeout(H,1)}}function H(){for(var t=0;Te>t;t+=2){var e=Fe[t],i=Fe[t+1];e(i),Fe[t]=void 0,Fe[t+1]=void 0}Te=0}function D(t,e){Y.async(t,e)}function W(){Y.on.apply(Y,arguments)}function X(){Y.off.apply(Y,arguments)}var Q={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(i,n){var r,o=e(this);r=o[i],r||(r=o[i]=[]),-1===t(r,n)&&r.push(n)},off:function(i,n){var r,o,s=e(this);return n?(r=s[i],o=t(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(t,i){var n,r,o=e(this);if(n=o[t])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof t)throw new TypeError("Argument must be an object");return s.prototype=t,new s},te=[],ee=function(t,e,i){1===te.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:Z(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;en;n++)this._eachEntry(i[n],n)},U.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;o(t)?t.constructor===i&&t._state!==ie?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(ne,e,t))},U.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===ie&&(this._remaining--,this._abortOnReject&&t===re?y(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&g(n,this._result)},U.prototype._makeResult=function(t,e,i){return i},U.prototype._willSettleAt=function(t,e){var i=this;m(t,void 0,function(t){i._settledAt(ne,e,t)},function(t){i._settledAt(re,e,t)})};var he=function(t,e){return new ae(this,t,!0,e).promise},ue=function(t,e){function i(t){d(o,t)}function n(t){y(o,t)}var r=this,o=new r(a,e);if(!G(t))return y(o,new TypeError("You must pass an array to race.")),o;for(var s=t.length,h=0;o._state===ie&&s>h;h++)m(r.resolve(t[h]),void 0,i,n);return o},ce=function(t,e){var i=this;if(t&&"object"==typeof t&&t.constructor===i)return t;var n=new i(a,e);return d(n,t),n},le=function(t,e){var i=this,n=new i(a,e);return y(n,t),n},pe="rsvp_"+Z()+"-",de=0,fe=x;x.cast=ce,x.all=he,x.race=ue,x.resolve=ce,x.reject=le,x.prototype={constructor:x,_guidKey:pe,_onerror:function(t){Y.trigger("error",t)},then:function(t,e,i){var n=this,r=n._state;if(r===ne&&!t||r===re&&!e)return Y.instrument&&ee("chained",this,this),this;n._onerror=null;var o=new this.constructor(a,i),s=n._result;if(Y.instrument&&ee("chained",n,o),r){var h=arguments[r-1];Y.async(function(){P(r,o,h,s)})}else m(n,o,t,e);return o},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}};var ge=new C,ye=new C,me=function(t,e){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,h=0;r>h;++h){if(i=arguments[h],!s){if(s=F(i),s===ye){var u=new fe(a);return y(u,ye.value),u}s&&s!==!0&&(i=N(s,i))}o[h]=i}var c=new fe(a);return o[r]=function(t,i){t?y(c,t):void 0===e?d(c,i):e===!0?d(c,k(arguments)):G(e)?d(c,T(arguments,e)):d(c,i)},s?L(c,o,t,n):q(c,o,t,n)};return i.__proto__=t,i},Se=function(t,e){return fe.all(t,e)};O.prototype=$(ae.prototype),O.prototype._superConstructor=ae,O.prototype._makeResult=w,O.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var ve=function(t,e){return new O(fe,t,e).promise},Ee=function(t,e){return fe.race(t,e)},Pe=V;V.prototype=$(ae.prototype),V.prototype._superConstructor=ae,V.prototype._init=function(){this._result={}},V.prototype._validateInput=function(t){return t&&"object"==typeof t},V.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},V.prototype._enumerate=function(){var t=this.promise,e=this._input,i=[];for(var n in e)t._state===ie&&e.hasOwnProperty(n)&&i.push({position:n,entry:e[n]});var r=i.length;this._remaining=r;for(var o,s=0;t._state===ie&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var Be=function(t,e){return new Pe(fe,t,e).promise};I.prototype=$(Pe.prototype),I.prototype._superConstructor=ae,I.prototype._makeResult=w,I.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var we,Ue=function(t,e){return new I(fe,t,e).promise},be=function(t){throw setTimeout(function(){throw t}),t},Je=function(t){var e={};return e.promise=new fe(function(t,i){e.resolve=t,e.reject=i},t),e},xe=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as map's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i)})},Ce=function(t,e){return fe.resolve(t,e)},Re=function(t,e){return fe.reject(t,e)},_e=function(t,e,i){return fe.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as filter's second argument.");for(var n=t.length,o=new Array(n),s=0;n>s;s++)o[s]=e(t[s]);return fe.all(o,i).then(function(e){for(var i=new Array(n),r=0,o=0;n>o;o++)e[o]&&(i[r]=t[o],r++);return i.length=r,i})})},Te=0,ke=function(t,e){Fe[Te]=t,Fe[Te+1]=e,Te+=2,2===Te&&we()},Ne="undefined"!=typeof window?window:{},qe=Ne.MutationObserver||Ne.WebKitMutationObserver,Le="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Fe=new Array(1e3);we="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?A():qe?M():Le?j():z(),Y.async=ke;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Oe=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Ve in Oe)Oe.hasOwnProperty(Ve)&&W(Ve,Oe[Ve])}var Ie={race:Ee,Promise:fe,allSettled:ve,hash:Be,hashSettled:Ue,denodeify:me,on:W,off:X,map:xe,filter:_e,resolve:Ce,reject:Re,all:Se,rethrow:be,defer:Je,EventTarget:Q,configure:i,async:D};"function"==typeof define&&define.amd?define(function(){return Ie}):"undefined"!=typeof module&&module.exports?module.exports=Ie:"undefined"!=typeof this&&(this.RSVP=Ie)}.call(this),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,u=new XMLHttpRequest,c=XMLHttpRequest.prototype;"overrideMimeType"in c||Object.defineProperty(c,"overrideMimeType",{value:function(){}}),i&&(u.withCredentials=!0),u.open("GET",t,!0);for(o in n)u.setRequestHeader(o,n[o]);return u.onreadystatechange=r,"blob"==e&&(u.responseType=a),"json"==e&&u.setRequestHeader("Accept","application/json"),"xml"==e&&u.overrideMimeType("text/xml"),u.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.extend=function(t){var e=[].slice.call(arguments,1);return e.forEach(function(e){e&&Object.getOwnPropertyNames(e).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(e,i))})}),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.core.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,EPUBJS.core.bounds=function(t){var e=window.getComputedStyle(t),i=["width","paddingRight","paddingLeft","marginRight","marginLeft","borderRightWidth","borderLeftWidth"],n=["height","paddingTop","paddingBottom","marginTop","marginBottom","borderTopWidth","borderBottomWidth"],r=0,o=0;return i.forEach(function(t){r+=parseFloat(e[t])||0}),n.forEach(function(t){o+=parseFloat(e[t])||0}),{height:o,width:r}},EPUBJS.core.borders=function(t){var e=window.getComputedStyle(t),i=["paddingRight","paddingLeft","marginRight","marginLeft","borderRightWidth","borderLeftWidth"],n=["paddingTop","paddingBottom","marginTop","marginBottom","borderTopWidth","borderBottomWidth"],r=0,o=0;return i.forEach(function(t){r+=parseFloat(e[t])||0}),n.forEach(function(t){o+=parseFloat(e[t])||0}),{height:o,width:r}},EPUBJS.core.windowBounds=function(){var t=window.innerWidth,e=window.innerHeight;return{top:0,left:0,right:t,bottom:e,width:t,height:e}},EPUBJS.core.cleanStringForXpath=function(t){var e=t.match(/[^'"]+|['"]/g);return e=e.map(function(t){return"'"===t?'"\'"':'"'===t?"'\"'":"'"+t+"'"}),"concat('',"+e.join(",")+")"},EPUBJS.core.indexOfTextNode=function(t){for(var e,i=t.parentNode,n=i.childNodes,r=-1,o=0;on?e[n].apply(this.context,o):void 0}.bind(this);return i?(t=this.hooks[n].apply(this.context,o),t&&"function"==typeof t.then?t.then(s):s()):(t=r.promise,r.resolve()),t},EPUBJS.Parser=function(){},EPUBJS.Parser.prototype.container=function(t){var e,i,n,r;return t?(e=t.querySelector("rootfile"))?(i=e.getAttribute("full-path"),n=EPUBJS.core.uri(i).directory,r=t.xmlEncoding,{packagePath:i,basePath:n,encoding:r}):(console.error("No RootFile Found"),void 0):(console.error("Container File Not Found"),void 0)},EPUBJS.Parser.prototype.identifier=function(t){var e;return t?(e=t.querySelector("metadata"),e?this.getElementText(e,"identifier"):(console.error("No Metadata Found"),void 0)):(console.error("Package File Not Found"),void 0)},EPUBJS.Parser.prototype.packageContents=function(t){var e,i,n,r,o,s,a,h,u,c=this;return t?(e=t.querySelector("metadata"))?(i=t.querySelector("manifest"))?(n=t.querySelector("spine"))?(r=c.manifest(i),o=c.findNavPath(i),s=c.findNcxPath(i),a=c.findCoverPath(i),h=Array.prototype.indexOf.call(n.parentNode.childNodes,n),u=c.spine(n,r),{metadata:c.metadata(e),spine:u,manifest:r,navPath:o,ncxPath:s,coverPath:a,spineNodeIndex:h}):(console.error("No Spine Found"),void 0):(console.error("No Manifest Found"),void 0):(console.error("No Metadata Found"),void 0):(console.error("Package File Not Found"),void 0)},EPUBJS.Parser.prototype.findNavPath=function(t){var e=t.querySelector("item[properties^='nav']");return e?e.getAttribute("href"):!1},EPUBJS.Parser.prototype.findNcxPath=function(t){var e=t.querySelector("item[media-type='application/x-dtbncx+xml']");return e?e.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(t){var e=t.querySelector("item[properties='cover-image']");return e?e.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(t){var e={},i=this;return e.title=i.getElementText(t,"title"),e.creator=i.getElementText(t,"creator"),e.description=i.getElementText(t,"description"),e.pubdate=i.getElementText(t,"date"),e.publisher=i.getElementText(t,"publisher"),e.identifier=i.getElementText(t,"identifier"),e.language=i.getElementText(t,"language"),e.rights=i.getElementText(t,"rights"),e.modified_date=i.querySelectorText(t,"meta[property='dcterms:modified']"),e.layout=i.querySelectorText(t,"meta[property='rendition:layout']"),e.orientation=i.querySelectorText(t,"meta[property='rendition:orientation']"),e.spread=i.querySelectorText(t,"meta[property='rendition:spread']"),e},EPUBJS.Parser.prototype.getElementText=function(t,e){var i,n=t.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",e);return n&&0!==n.length?(i=n[0],i.childNodes.length?i.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(t,e){var i=t.querySelector(e);return i&&i.childNodes.length?i.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(t){var e={},i=t.querySelectorAll("item"),n=Array.prototype.slice.call(i);return n.forEach(function(t){var i=t.getAttribute("id"),n=t.getAttribute("href")||"",r=t.getAttribute("media-type")||"",o=t.getAttribute("properties")||"";e[i]={href:n,type:r,properties:o.length?o.split(" "):[]}}),e},EPUBJS.Parser.prototype.spine=function(t){{var e=[],i=t.getElementsByTagName("itemref"),n=Array.prototype.slice.call(i);new EPUBJS.EpubCFI}return n.forEach(function(t,i){var n=t.getAttribute("idref"),r=t.getAttribute("properties")||"",o=r.length?r.split(" "):[],s={idref:n,linear:t.getAttribute("linear")||"",properties:o,index:i};e.push(s)}),e},EPUBJS.Parser.prototype.nav=function(t){function e(t){var e=[];return Array.prototype.slice.call(t.childNodes).forEach(function(t){"ol"==t.tagName&&Array.prototype.slice.call(t.childNodes).forEach(function(t){"li"==t.tagName&&e.push(t)})}),e}function i(t){var e=null;return Array.prototype.slice.call(t.childNodes).forEach(function(t){("a"==t.tagName||"span"==t.tagName)&&(e=t)}),e}function n(t){var r=[],o=e(t),s=Array.prototype.slice.call(o),a=s.length;return 0===a?!1:(s.forEach(function(e){var o=e.getAttribute("id")||!1,s=i(e),a=s.getAttribute("href")||"",h=s.textContent||"",u=a.split("#"),c=(u[0],n(e));r.push({id:o,href:a,label:h,subitems:c,parent:t?t.getAttribute("id"):null})}),r)}var r=t.querySelector('nav[*|type="toc"]');return r?n(r):[]},EPUBJS.Parser.prototype.ncx=function(t){function e(i){var n=[],r=t.evaluate("*[local-name()='navPoint']",i,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),o=r.snapshotLength;if(0===o)return[];for(var s=o-1;s>=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,u=a.querySelector("content"),c=u.getAttribute("src"),l=a.querySelector("navLabel"),p=l.textContent?l.textContent:"",d=c.split("#"),f=(d[0],e(a));n.unshift({id:h,href:c,label:p,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},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,u,c={},l=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(c.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]||"")?(c.spinePos=parseInt(e)/2-1||0,s=e.match(/\[(.*)\]/),c.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),c.steps=[],a.forEach(function(t){var e;t&&(e=l(t),c.steps.push(e))}),u=parseInt(h),isNaN(u)||(u%2===0?c.steps.push(l(h)):c.steps.push({type:"text",index:(u-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(c.characterOffset=parseInt(r.split("[")[0]),c.textLocationAssertion=o[1]):c.characterOffset=parseInt(r),c):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(t,e,i){var n,r,o,s,a=e||document,h=i||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,t.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffset-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.replace={},EPUBJS.replace.links=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-1&&(this.observer=this.observe(this.document.body)),this.imageLoadListeners(),this.mediaQueryListeners(),this.resizeListenters()},EPUBJS.View.prototype.resizeListenters=function(){clearTimeout(this.expanding),this.expanding=setTimeout(this.expand.bind(this),350)},EPUBJS.View.prototype.mediaQueryListeners=function(){for(var t=this.document.styleSheets,e=function(t){t.matches&&this.expand()}.bind(this),i=0;i-1&&(id=t.substring(t.indexOf("#")),el=this.document.getElementById(id)))return el.getBoundingClientRect();return{left:0,top:0}}},EPUBJS.View.prototype.addCss=function(t){var e=document.createElement("link"),i=!1;return new RSVP.Promise(function(n){return this.document?(e.type="text/css",e.rel="stylesheet",e.href=t,e.onload=e.onreadystatechange=function(){i||this.readyState&&"complete"!=this.readyState||(i=!0,setTimeout(function(){n(!0)},1))},this.document.head.appendChild(e),void 0):(n(!1),void 0)}.bind(this))},EPUBJS.View.prototype.addStylesheetRules=function(t){var e,i=document.createElement("style");if(this.document){this.document.head.appendChild(i),e=i.sheet;for(var n=0,r=t.length;r>n;n++){var o=1,s=t[n],a=t[n][0],h="";"[object Array]"===Object.prototype.toString.call(s[1][0])&&(s=s[1],o=0);for(var u=s.length;u>o;o++){var c=s[o];h+=c[0]+":"+c[1]+(c[2]?" !important":"")+";\n"}e.insertRule(a+"{"+h+"}",e.cssRules.length)}}},RSVP.EventTarget.mixin(EPUBJS.View.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){},EPUBJS.Layout.Reflowable.prototype.calculate=function(t,e,i,n){var r,o,s,a=n||1,h=Math.floor(t),u=h%2===0?h:h-1,c=Math.floor(u/8),l=i>=0?i:c%2===0?c:c-1;r=a>1?Math.floor((u-l)/a):u,o=r*a,s=(r+l)*a,this.columnAxis=EPUBJS.core.prefixed("columnAxis"),this.columnGap=EPUBJS.core.prefixed("columnGap"),this.columnWidth=EPUBJS.core.prefixed("columnWidth"),this.columnFill=EPUBJS.core.prefixed("columnFill"),this.width=u,this.height=e,this.spread=o,this.delta=s,this.column=r,this.gap=l,this.divisor=a},EPUBJS.Layout.Reflowable.prototype.format=function(t){var e=t.document.documentElement,i=t.document.body;e.style.overflow="hidden",e.style.width=this.width+"px",i.style.height=this.height+"px",i.style[this.columnAxis]="horizontal",i.style[this.columnFill]="auto",i.style[this.columnGap]=this.gap+"px",i.style[this.columnWidth]=this.column+"px",t.iframe.style.marginRight=this.gap+"px"},EPUBJS.Layout.Reflowable.prototype.count=function(t){var e=t.root().scrollWidth,i=Math.ceil(e/this.spread);return{spreads:i,pages:i*this.divisor}},EPUBJS.Layout.Fixed=function(){},EPUBJS.Layout.Fixed.prototype.calculate=function(){},EPUBJS.Layout.Fixed.prototype.format=function(t){var e,i,n=t.document.documentElement,r=documentElement.querySelector("[name=viewport");r&&r.hasAttribute("content")&&(content=r.getAttribute("content"),contents=content.split(","),contents[0]&&(e=contents[0].replace("width=","")),contents[1]&&(i=contents[1].replace("height=",""))),t.resize(e,i),n.style.overflow="auto"},EPUBJS.Layout.Fixed.prototype.count=function(){return{spreads:1,pages:1}},EPUBJS.Layout.Scroll=function(){},EPUBJS.Layout.Scroll.prototype.calculate=function(t){this.spread=t,this.column=t,this.gap=0},EPUBJS.Layout.Scroll.prototype.format=function(t){var e=t.document.documentElement;e.style.width="auto",e.style.height="auto"},EPUBJS.Layout.Scroll.prototype.count=function(){return{spreads:1,pages:1}},EPUBJS.Rendition=function(t,e){this.settings=EPUBJS.core.extend(this.settings||{},{infinite:!0,hidden:!1,width:!1,height:null,layoutOveride:null,axis:"vertical"}),EPUBJS.core.extend(this.settings,e),this.viewSettings={},this.book=t,this.views=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.layout=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(EPUBJS.replace.links.bind(this)),this.epubcfi=new EPUBJS.EpubCFI,this.q=new EPUBJS.Queue(this),this.q.enqueue(this.book.opened),this.q.enqueue(this.parseLayoutProperties)},EPUBJS.Rendition.prototype.initialize=function(t){{var e,i=t||{},n=i.height,r=i.width;i.hidden||!1}return i.height&&EPUBJS.core.isNumber(i.height)&&(n=i.height+"px"),i.width&&EPUBJS.core.isNumber(i.width)&&(r=i.width+"px"),e=document.createElement("div"),e.id="epubjs-container:"+EPUBJS.core.uuid(),e.classList.add("epub-container"),e.style.fontSize="0",e.style.wordSpacing="0",e.style.lineHeight="0",e.style.verticalAlign="top","horizontal"===this.settings.axis&&(e.style.whiteSpace="nowrap"),r&&(e.style.width=r),n&&(e.style.height=n),e.style.overflow=this.settings.overflow,e},EPUBJS.Rendition.wrap=function(t){var e=document.createElement("div");return e.style.visibility="hidden",e.style.overflow="hidden",e.style.width="0",e.style.height="0",e.appendChild(t),e},EPUBJS.Rendition.prototype.attachTo=function(t){return this.container=this.initialize({width:this.settings.width,height:this.settings.height}),EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.settings.hidden?(this.wrapper=this.wrap(this.container),this.element.appendChild(this.wrapper)):this.element.appendChild(this.container),this.attachListeners(),this.stageSize(),this.applyLayoutMethod(),this.trigger("attached"),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Rendition.prototype.attachListeners=function(){EPUBJS.core.isNumber(this.settings.width)&&EPUBJS.core.isNumber(this.settings.height)||window.addEventListener("resize",this.onResized.bind(this),!1)},EPUBJS.Rendition.prototype.bounds=function(){return this.container.getBoundingClientRect()},EPUBJS.Rendition.prototype.display=function(t){return this.q.enqueue(this._display,t)},EPUBJS.Rendition.prototype._display=function(t){var e,i,n,r,o=new RSVP.defer,s=o.promise;return this.epubcfi.isCfiString(t)?(n=this.epubcfi.parse(t),r=n.spinePos,e=this.book.spine.get(r)):e=this.book.spine.get(t),this.displaying=!0,this.hide(),e?(i=this.createView(e),this.q.enqueue(this.append,i),this.show(),this.hooks.display.trigger(i),o.resolve(this)):o.reject(new Error("No Section Found")),s},EPUBJS.Rendition.prototype.moveTo=function(){},EPUBJS.Rendition.prototype.render=function(t,e){return t.create(),t.onLayout=this.layout.format.bind(this.layout),this.resizeView(t),t.render(this.book.request).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return this.hooks.layout.trigger(t)}.bind(this)).then(function(){return t.display()}.bind(this)).then(function(t){0!=e&&this.hidden===!1&&this.q.enqueue(function(t){t.show()},t),this.trigger("rendered",t.section)}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Rendition.prototype.afterDisplayed=function(t){this.trigger("displayed",t.section)},EPUBJS.Rendition.prototype.append=function(t){return this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=this.afterDisplayed.bind(this),this.render(t)},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){this._remove(t)}.bind(this)),this.views=[]},EPUBJS.Rendition.prototype.remove=function(t){var e=this.views.indexOf(t);e>-1&&this.views.splice(e,1),this._remove(t)},EPUBJS.Rendition.prototype._remove=function(t){t.off("resized"),t.displayed&&t.destroy(),this.container.removeChild(t.element),t=null},EPUBJS.Rendition.prototype.resizeView=function(t){"pre-paginated"===this.globalLayoutProperties.layout?t.lock("both",this.stage.width,this.stage.height):t.lock("width",this.stage.width,this.stage.height)},EPUBJS.Rendition.prototype.stageSize=function(t,e){var i,n=t||this.settings.width,r=e||this.settings.height;return n===!1&&(i=this.element.getBoundingClientRect(),i.width&&(n=i.width,this.container.style.width=i.width+"px")),r===!1&&(i=i||this.element.getBoundingClientRect(),i.height&&(r=i.height,this.container.style.height=i.height+"px")),n&&!EPUBJS.core.isNumber(n)&&(i=this.container.getBoundingClientRect(),n=i.width),r&&!EPUBJS.core.isNumber(r)&&(i=i||this.container.getBoundingClientRect(),r=i.height),this.containerStyles=window.getComputedStyle(this.container),this.containerPadding={left:parseFloat(this.containerStyles["padding-left"])||0,right:parseFloat(this.containerStyles["padding-right"])||0,top:parseFloat(this.containerStyles["padding-top"])||0,bottom:parseFloat(this.containerStyles["padding-bottom"])||0},this.stage={width:n-this.containerPadding.left-this.containerPadding.right,height:r-this.containerPadding.top-this.containerPadding.bottom},this.stage},EPUBJS.Rendition.prototype.applyLayoutMethod=function(){this.layout=new EPUBJS.Layout.Scroll,this.updateLayout(),this.map=new EPUBJS.Map(this.layout)},EPUBJS.Rendition.prototype.updateLayout=function(){this.layout.calculate(this.stage.width,this.stage.height)},EPUBJS.Rendition.prototype.resize=function(t,e){this.stageSize(t,e),this.updateLayout(),this.views.forEach(this.resizeView.bind(this)),this.trigger("resized",{width:this.stage.width,height:this.stage.height})},EPUBJS.Rendition.prototype.onResized=function(){this.resize()},EPUBJS.Rendition.prototype.createView=function(t){return new EPUBJS.View(t,this.viewSettings)},EPUBJS.Rendition.prototype.next=function(){return this.q.enqueue(function(){var t,e;return this.views.length?(t=this.views[0].section.next(),t?(e=this.createView(t),this.append(e)):void 0):void 0})},EPUBJS.Rendition.prototype.prev=function(){return this.q.enqueue(function(){var t,e;return this.views.length?(t=this.views[0].section.prev(),t?(e=this.createView(t),this.append(e)):void 0):void 0})},EPUBJS.Rendition.prototype.parseLayoutProperties=function(t){var e=t||this.book.package.metadata,i=this.layoutOveride&&this.layoutOveride.layout||e.layout||"reflowable",n=this.layoutOveride&&this.layoutOveride.spread||e.spread||"auto",r=this.layoutOveride&&this.layoutOveride.orientation||e.orientation||"auto";return this.globalLayoutProperties={layout:i,spread:n,orientation:r},this.globalLayoutProperties},EPUBJS.Rendition.prototype.current=function(){var t=this.visible();return t.length?t[t.length-1]:null},EPUBJS.Rendition.prototype.isVisible=function(t,e,i,n){var r=t.position(),o=n||this.container.getBoundingClientRect();return"horizontal"===this.settings.axis&&r.right>o.left-e&&!(r.left>=o.right+i)?!0:"vertical"===this.settings.axis&&r.bottom>o.top-e&&!(r.top>=o.bottom+i)?!0:!1},EPUBJS.Rendition.prototype.visible=function(){for(var t,e,i=this.bounds(),n=[],r=0;r=0;r--)if(t=this.views[r],e=t.bounds().top,ethis.settings.offsetDelta||this.scrollDeltaHorz>this.settings.offsetDelta)&&(this.q.enqueue(this.check),this.scrollDeltaVert=0,this.scrollDeltaHorz=0),this.scrollDeltaVert+=Math.abs(scrollTop-this.prevScrollTop),this.scrollDeltaHorz+=Math.abs(scrollLeft-this.prevScrollLeft),this.settings.height?(this.prevScrollTop=this.container.scrollTop,this.prevScrollLeft=this.container.scrollLeft):(this.prevScrollTop=window.scrollY,this.prevScrollLeft=window.scrollX),clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(function(){this.scrollDeltaVert=0,this.scrollDeltaHorz=0}.bind(this),150),this.scrolled=!1),this.tick.call(window,this.onScroll.bind(this))},EPUBJS.Continuous.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.settings.height?(t&&(this.container.scrollLeft+=t),e&&(this.container.scrollTop+=e)):window.scrollBy(t,e),this.scrolled=!0},EPUBJS.Continuous.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!0),this.settings.height?(this.container.scrollLeft=t,this.container.scrollTop=e):window.scrollTo(t,e),this.scrolled=!0},EPUBJS.Continuous.prototype.resizeView=function(t){"horizontal"===this.settings.axis?t.lock("height",this.stage.width,this.stage.height):t.lock("width",this.stage.width,this.stage.height)},EPUBJS.Continuous.prototype.currentLocation=function(){{var t,e,i=this.visible();this.container.getBoundingClientRect()}return 1===i.length?this.map.page(i[0]):i.length>1?(t=this.map.page(i[0]),e=this.map.page(i[i.length-1]),{start:t.start,end:e.end}):void 0},EPUBJS.Paginate=function(t,e){EPUBJS.Continuous.apply(this,arguments),this.settings=EPUBJS.core.extend(this.settings||{},{width:600,height:400,axis:"horizontal",forceSingle:!1,minSpreadWidth:800,gap:"auto",overflow:"hidden",infinite:!1}),EPUBJS.core.extend(this.settings,e),this.isForcedSingle=this.settings.forceSingle,this.viewSettings={axis:this.settings.axis},this.start() +},EPUBJS.Paginate.prototype=Object.create(EPUBJS.Continuous.prototype),EPUBJS.Paginate.prototype.constructor=EPUBJS.Paginate,EPUBJS.Paginate.prototype.determineSpreads=function(t){return this.isForcedSingle||!t||this.bounds().width1?(t=a.left-s[0].position().left,i=t+this.layout.column,e=a.left+this.layout.spread-s[s.length-1].position().left,n=e+this.layout.column,r=this.map.page(s[0],t,i),o=this.map.page(s[s.length-1],e,n),{start:r.start,end:o.end}):void 0},EPUBJS.Paginate.prototype.resize=function(t,e){this.q.clear(),this.stageSize(t,e),this.updateLayout(),this.display(this.location.start),this.trigger("resized",{width:this.stage.width,height:this.stage.height})},EPUBJS.Paginate.prototype.onResized=function(){this.clear(),clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout(function(){this.resize()}.bind(this),150)},EPUBJS.Paginate.prototype.adjustImages=function(t){return t.addStylesheetRules([["img",["max-width",this.layout.spread+"px"],["max-height",this.layout.height+"px"]]]),new RSVP.Promise(function(t){setTimeout(function(){t()},1)})},EPUBJS.Map=function(t){this.layout=t},EPUBJS.Map.prototype.section=function(t){var e=this.findRanges(t),i=this.rangeListToCfiList(t,e);return i},EPUBJS.Map.prototype.page=function(t,e,i){var n=t.document.body;return this.rangePairToCfiPair(t.section,{start:this.findStart(n,e,i),end:this.findEnd(n,e,i)})},EPUBJS.Map.prototype.walk=function(t,e){for(var i,n,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode:function(t){return t.data.trim().length>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},!1);(i=r.nextNode())&&!(n=e(i)););return n},EPUBJS.Map.prototype.findRanges=function(t){for(var e,i,n=[],r=this.layout.count(t),o=this.layout.column,s=this.layout.gap,a=0;a=e&&i>=n?t:r>e?t:(s=t,o.push(t),void 0)}))return this.findTextStartRange(r,e,i);return this.findTextStartRange(s,e,i)},EPUBJS.Map.prototype.findEnd=function(t,e,i){for(var n,r,o=[t],s=t;o.length;)if(n=o.shift(),r=this.walk(n,function(t){var e,n,r,a;return t.nodeType==Node.TEXT_NODE?(a=document.createRange(),a.selectNodeContents(t),r=a.getBoundingClientRect()):r=t.getBoundingClientRect(),e=r.left,n=r.right,e>i&&s?s:n>i?t:(s=t,o.push(t),void 0)}))return this.findTextEndRange(r,e,i);return this.findTextEndRange(s,e,i)},EPUBJS.Map.prototype.findTextStartRange=function(t,e){for(var i,n,r,o=this.splitTextNodeIntoRanges(t),s=0;s=e)return n;i=n}return o[0]},EPUBJS.Map.prototype.findTextEndRange=function(t,e,i){for(var n,r,o,s=this.splitTextNodeIntoRanges(t),a=0;ai&&n)return n;if(o.right>i)return r;n=r}return s[s.length-1]},EPUBJS.Map.prototype.splitTextNodeIntoRanges=function(t,e){var i,n=[],r=t.textContent||"",o=r.trim(),s=t.ownerDocument,a=e||" ";if(pos=o.indexOf(a),-1===pos||t.nodeType!=Node.TEXT_NODE)return i=s.createRange(),i.selectNodeContents(t),[i];for(i=s.createRange(),i.setStart(t,0),i.setEnd(t,pos),n.push(i),i=!1;-1!=pos;)pos=o.indexOf(a,pos+1),pos>0&&(i&&(i.setEnd(t,pos),n.push(i)),i=s.createRange(),i.setStart(t,pos+1));return i&&(i.setEnd(t,o.length),n.push(i)),n},EPUBJS.Map.prototype.rangePairToCfiPair=function(t,e){var i=e.start,n=e.end;return i.collapse(!0),n.collapse(!0),startCfi=t.cfiFromRange(i),endCfi=t.cfiFromRange(n),{start:startCfi,end:endCfi}},EPUBJS.Map.prototype.rangeListToCfiList=function(t,e){for(var i,n=[],r=0;r