From f998e5be0ae6317bbfa93136772e2d86c6917f15 Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Mon, 25 May 2015 20:30:07 -0400 Subject: [PATCH] Added windowBounds, enqueue checks after render --- dist/epub.js | 30 ++++++++++++++++++------------ dist/epub.min.js | 4 ++-- lib/epubjs/continuous.js | 14 ++------------ lib/epubjs/core.js | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/dist/epub.js b/dist/epub.js index 841ed7f..e8eb96c 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -2715,6 +2715,22 @@ EPUBJS.core.borders = function(el) { width: width } +}; + +EPUBJS.core.windowBounds = function() { + + var width = window.innerWidth; + var height = window.innerHeight; + + return { + top: 0, + left: 0, + right: width, + bottom: height, + width: width, + height: height + } + }; EPUBJS.Queue = function(_context){ this._q = []; @@ -5605,18 +5621,8 @@ EPUBJS.Continuous.prototype.check = function(){ var checking = new RSVP.defer(); var container;//this.container.getBoundingClientRect(); - // Temp if(!this.settings.height) { - var width = window.innerWidth; - var height = window.innerHeight; - container = { - top: 0, - left: 0, - right: width, - bottom: height, - width: width, - height: height - } + container = EPUBJS.core.windowBounds(); } else { container = this.container.getBoundingClientRect(); } @@ -5634,7 +5640,7 @@ EPUBJS.Continuous.prototype.check = function(){ .then(function(){ // Check to see if anything new is on screen after rendering - return this.check(); + this.q.enqueue(this.check); }.bind(this)); }); diff --git a/dist/epub.min.js b/dist/epub.min.js index add68a0..ed825d9 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,2 +1,2 @@ -"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(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,u=[],c=0,l=a.length;l>c;c++)u.push("exports"===a[c]?o={}:i(r(a[c])));var p=h.apply(this,u);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 x.error=e,x}}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?c(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===J?d(t,e._result):f(e,void 0,function(i){e!==i?c(t,i):p(t,i)},function(e){d(t,e)})}function u(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===x?d(t,x.error):void 0===i?p(t,e):P(i)?a(t,e,i):p(t,e)}}function c(t,e){t===e?p(t,e):E(e)?u(t,e):p(t,e)}function l(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&&w("fulfilled",t):B.async(g,t))}function d(t,e){t._state===b&&(t._state=J,t._result=e,B.async(l,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+J]=n,0===o&&t._state&&B.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(B.instrument&&w(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=l[t],i=l[t+1];e(i),l[t]=void 0,l[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){l[s]=t,l[s+1]=e,s+=2,2===s&&a()};var a,h="undefined"!=typeof window?window:{},u=h.MutationObserver||h.WebKitMutationObserver,c="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,l=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():u?i():c?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===l?{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?u(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&u(this.promise,this._result))):h(this.promise,this._validationError())}var o=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,u=e.fulfill,c=e.subscribe,l=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(l,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&&u(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;c(t,void 0,function(t){i._settledAt(l,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"],u=e["default"],c=n.o_create;o.prototype=c(h.prototype),o.prototype._superConstructor=u,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],u=i[1];if(h)r(h);else if(o)n(i.slice(1));else if(s){var c,l,p={},d=i.slice(1);for(l=0;la;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,u,c){"use strict";function l(){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=_++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),v!==t&&(m(t)||l(),this instanceof d||p(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),m=(n.objectOrFunction,n.isFunction),y=n.now,v=r.noop,S=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,P=r.invokeCallback,w=r.FULFILLED,B=o["default"],b=s["default"],U=a["default"],J=h["default"],x=u["default"],C="rsvp_"+y()+"-",_=0;c["default"]=d,d.cast=B,d.all=b,d.race=U,d.resolve=J,d.reject=x,d.prototype={constructor:d,_id:void 0,_guidKey:C,_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(v,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===w&&t?f.async(function(){P(o,r,t,s)}):S(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(l,t)}function u(t){s(l,t)}var c=this,l=new c(r,e);if(!n(t))return s(l,new TypeError("You must pass an array to race.")),l;for(var p=t.length,d=0;l._state===h&&p>d;d++)a(c.resolve(t[d]),void 0,i,u);return l}}),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,u,c,l,p,d,f,g,m){"use strict";function y(t,e){R.async(t,e)}function v(){R.on.apply(R,arguments)}function S(){R.off.apply(R,arguments)}var E=t["default"],P=e["default"],w=i["default"],B=n["default"],b=r["default"],U=o["default"],J=s["default"],x=a["default"],C=h["default"],_=u["default"],R=c.config,k=c.configure,T=l["default"],N=p["default"],q=d["default"],F=f["default"],O=g["default"];if(R.async=O,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var L=window.__PROMISE_INSTRUMENTATION__;k("instrument",!0);for(var A in L)L.hasOwnProperty(A)&&v(A,L[A])}m.Promise=E,m.EventTarget=P,m.all=B,m.allSettled=b,m.race=U,m.hash=J,m.hashSettled=x,m.rethrow=C,m.defer=_,m.denodeify=w,m.configure=k,m.on=v,m.off=S,m.resolve=N,m.reject=q,m.async=y,m.map=T,m.filter=F}),t.RSVP=i("rsvp")}(self),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.Queue=function(t){this._q=[],this.context=t,this.tick=EPUBJS.core.requestAnimationFrame,this.running=!1},EPUBJS.Queue.prototype.enqueue=function(){var t,e,i,n=[].shift.call(arguments),r=arguments;return"function"==typeof n?(t=new RSVP.defer,e=t.promise,i={task:n,args:r,deferred:t,promise:e}):i={promise:n},this._q.push(i),i.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e;return this._q.length?(t=this._q.shift(),e=t.task,e?e.apply(this.context,t.args).then(function(){t.deferred.resolve.apply(t.context||this.context,arguments)}.bind(this)):t.promise):(t=new RSVP.defer,t.deferred.resolve(),t.promise)},EPUBJS.Queue.prototype.flush=function(){for(;this._q.length;)this.dequeue()},EPUBJS.Queue.prototype.run=function(){!this.running&&this._q.length&&(this.running=!0,this.dequeue().then(function(){this.running=!1}.bind(this))),this.tick.call(window,this.run.bind(this))},EPUBJS.Queue.prototype.clear=function(){this._q=[]},EPUBJS.Queue.prototype.length=function(){return this._q.length},EPUBJS.Task=function(t){return function(){var e=arguments||[];return new RSVP.Promise(function(i){var n=function(t){i(t)};e.push(n),t.apply(this,e)}.bind(this))}},EPUBJS.Hook=function(t){this.context=t||this,this.hooks=[]},EPUBJS.Hook.prototype.register=function(t){this.hooks.push(t)},EPUBJS.Hook.prototype.trigger=function(){var t,e=this.hooks.length,i=0,n=new RSVP.defer,r=arguments;return e?(t=this.hooks[i].apply(this.context,r),t.then(function(){return i+=1,e>i?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}):void console.error("No RootFile Found"):void console.error("Container File Not Found")},EPUBJS.Parser.prototype.identifier=function(t){var e;return t?(e=t.querySelector("metadata"),e?this.getElementText(e,"identifier"):void console.error("No Metadata Found")):void console.error("Package File Not Found")},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}):void console.error("No Spine Found"):void console.error("No Manifest Found"):void console.error("No Metadata Found"):void console.error("Package File Not Found")},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);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)||c.steps.push(u%2===0?l(h):{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})},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()},EPUBJS.View.prototype.expand=function(){var t=this.lockedWidth,e=this.lockedHeight;t&&!e&&(e=this.document.documentElement.scrollHeight),e&&!t&&(t=this.document.body.scrollWidth),this.resize(t,e)},EPUBJS.View.prototype.mediaQueryListeners=function(){for(var t=this.document.styleSheets,e=function(t){t.matches&&this.expand()}.bind(this),i=0;i=0?i:u%2===0?u:u-1;return r=s>1?Math.floor((h-c)/s):h,o=(r+c)*s,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=h,this.height=e,this.spread=o,this.column=r,this.gap=c,this.divisor=s,this},EPUBJS.Layout.Reflowable.prototype.format=function(t){var e=t.document.documentElement,i=t.document.body;e.style.overflow="hidden",i.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.documentElement.scrollWidth,i=Math.ceil(e/this.spreadWidth);return{spreads:i,pages:i*this.divisor}},EPUBJS.Layout.Fixed=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.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:!1,layoutOveride:null}),EPUBJS.core.extend(this.settings,e),this.viewSettings={},this.book=t,this.settings.hidden&&(this.wrapper=this.wrap(this.container)),this.views=[],this.hooks={},this.hooks.layout=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(EPUBJS.replace.links.bind(this)),this.q=new EPUBJS.Queue(this),this.q.enqueue(this.book.opened),this.book.opened.then(function(){this.globalLayoutProperties=this.parseLayoutProperties(this.book.package.metadata)}.bind(this))},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.element.appendChild(this.container),this.attachListeners(),this.stageSize(),this.layoutMethod(),this.trigger("attached"),void this.q.run()):void console.error("Not an Element")},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(function(t){var e,i=new RSVP.defer,n=i.promise,r=this.book.spine.get(t);return this.displaying=!0,r?(e=this.createView(r),this.q.enqueue(this.append,e),i.resolve(this)):i.reject(new Error("No Section Found")),n},t)},EPUBJS.Rendition.prototype.moveTo=function(){},EPUBJS.Rendition.prototype.render=function(t){return t.create(),t.onLayout=this.layout.format.bind(this.layout),this.resizeView(t),t.display(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.show()}.bind(this)).then(function(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.onShown=this.afterDisplayed.bind(this),this.render(t)},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){this.remove(t)}.bind(this))},EPUBJS.Rendition.prototype.remove=function(t){var e=this.views.indexOf(t);e>-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.resizeView=function(t){"pre-paginated"===this.globalLayoutProperties.layout?t.lock(this.stage.width,this.stage.height):t.lock(this.stage.width,null)},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},EPUBJS.Rendition.prototype.resize=function(t,e){this.stageSize(t,e),this.layoutMethod(),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=this.layoutOveride&&this.layoutOveride.layout||t.layout||"reflowable",i=this.layoutOveride&&this.layoutOveride.spread||t.spread||"auto",n=this.layoutOveride&&this.layoutOveride.orientation||t.orientation||"auto";return{layout:e,spread:i,orientation:n}},RSVP.EventTarget.mixin(EPUBJS.Rendition.prototype),EPUBJS.Continuous=function(t,e){EPUBJS.Rendition.apply(this,arguments),this.settings=EPUBJS.core.extend(this.settings||{},{infinite:!0,hidden:!1,width:!1,height:!1,overflow:"auto",axis:"vertical",offset:500,offsetDelta:100}),EPUBJS.core.extend(this.settings,e),this.settings.hidden&&(this.wrapper=this.wrap(this.container))},EPUBJS.Continuous.prototype=Object.create(EPUBJS.Rendition.prototype),EPUBJS.Continuous.prototype.constructor=EPUBJS.Continuous,EPUBJS.Continuous.prototype.attachListeners=function(){EPUBJS.core.isNumber(this.settings.width)&&EPUBJS.core.isNumber(this.settings.height)||window.addEventListener("resize",this.onResized.bind(this),!1),this.settings.infinite&&this.start()},EPUBJS.Continuous.prototype.display=function(t){return this.q.enqueue(function(t){var e,i=new RSVP.defer,n=i.promise,r=this.book.spine.get(t);return this.displaying=!0,r?(e=new EPUBJS.View(r,this.viewSettings),this.q.enqueue(this.fill,e),this.q.enqueue(this.check),i.resolve(this)):i.reject(new Error("No Section Found")),n},t)},EPUBJS.Continuous.prototype.moveTo=function(){},EPUBJS.Continuous.prototype.afterDisplayed=function(t){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(i=new EPUBJS.View(n,this.viewSettings),this.q.enqueue(this.append,i)),0===o&&r&&(e=new EPUBJS.View(r,this.viewSettings),this.q.enqueue(this.prepend,e)),t.onShown=this.afterDisplayed.bind(this),this.trigger("displayed",t.section)},EPUBJS.Continuous.prototype.removeShownListeners=function(t){t.onShown=function(){}},EPUBJS.Continuous.prototype.append=function(t){return this.views.push(t),this.container.appendChild(t.element),t.onShown=this.afterDisplayed.bind(this),this.check()},EPUBJS.Continuous.prototype.prepend=function(t){return this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onShown=this.afterDisplayed.bind(this),t.on("resized",this.counter.bind(this)),this.check()},EPUBJS.Continuous.prototype.counter=function(t){"vertical"===this.settings.axis?this.scrollBy(0,t.heightDelta,!0):this.scrollBy(t.widthDelta,0,!0)},EPUBJS.Continuous.prototype.fill=function(t){return this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onShown=this.afterDisplayed.bind(this),this.render(t)},EPUBJS.Continuous.prototype.insert=function(t,e){return this.views.splice(e,0,t),e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.off("resized"),t.shown&&t.destroy(),t=null},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.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();return"horizontal"===this.settings.axis&&i.right>=n.left-this.settings.offset&&!(i.left>=n.right+this.settings.offset)?!0:"vertical"===this.settings.axis&&i.bottom>=n.top-this.settings.offset&&!(i.top>=n.bottom+this.settings.offset)?!0:!1},EPUBJS.Continuous.prototype.check=function(){var t,e=new RSVP.defer;if(this.settings.height)t=this.container.getBoundingClientRect();else{var i=window.innerWidth,n=window.innerHeight;t={top:0,left:0,right:i,bottom:n,width:i,height:n}}return this.views.forEach(function(e){var i=this.isVisible(e,t);i?e.shown||this.rendering||this.q.enqueue(function(){return this.render(e).then(function(){return this.check()}.bind(this))}):e.shown&&e.destroy()}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.q.enqueue(this.trim)}.bind(this),250),e.resolve(),e.promise},EPUBJS.Continuous.prototype.trim=function(){var t=new RSVP.defer,e=!0;return this.views.forEach(function(t,i){var n=i>0?this.views[i-1].shown:!1,r=i+1=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?(this.container.scrollLeft+=t,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(null,this.stage.height):t.lock(this.stage.width,null)},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().widthr;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,u=[],c=0,l=a.length;l>c;c++)u.push("exports"===a[c]?o={}:i(r(a[c])));var p=h.apply(this,u);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 x.error=e,x}}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?c(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===J?d(t,e._result):f(e,void 0,function(i){e!==i?c(t,i):p(t,i)},function(e){d(t,e)})}function u(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===x?d(t,x.error):void 0===i?p(t,e):P(i)?a(t,e,i):p(t,e)}}function c(t,e){t===e?p(t,e):E(e)?u(t,e):p(t,e)}function l(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&&w("fulfilled",t):B.async(g,t))}function d(t,e){t._state===b&&(t._state=J,t._result=e,B.async(l,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+J]=n,0===o&&t._state&&B.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(B.instrument&&w(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=l[t],i=l[t+1];e(i),l[t]=void 0,l[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){l[s]=t,l[s+1]=e,s+=2,2===s&&a()};var a,h="undefined"!=typeof window?window:{},u=h.MutationObserver||h.WebKitMutationObserver,c="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,l=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():u?i():c?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===l?{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?u(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&u(this.promise,this._result))):h(this.promise,this._validationError())}var o=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,u=e.fulfill,c=e.subscribe,l=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(l,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&&u(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;c(t,void 0,function(t){i._settledAt(l,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"],u=e["default"],c=n.o_create;o.prototype=c(h.prototype),o.prototype._superConstructor=u,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],u=i[1];if(h)r(h);else if(o)n(i.slice(1));else if(s){var c,l,p={},d=i.slice(1);for(l=0;la;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,u,c){"use strict";function l(){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=_++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),v!==t&&(m(t)||l(),this instanceof d||p(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),m=(n.objectOrFunction,n.isFunction),y=n.now,v=r.noop,S=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,P=r.invokeCallback,w=r.FULFILLED,B=o["default"],b=s["default"],U=a["default"],J=h["default"],x=u["default"],C="rsvp_"+y()+"-",_=0;c["default"]=d,d.cast=B,d.all=b,d.race=U,d.resolve=J,d.reject=x,d.prototype={constructor:d,_id:void 0,_guidKey:C,_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(v,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===w&&t?f.async(function(){P(o,r,t,s)}):S(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(l,t)}function u(t){s(l,t)}var c=this,l=new c(r,e);if(!n(t))return s(l,new TypeError("You must pass an array to race.")),l;for(var p=t.length,d=0;l._state===h&&p>d;d++)a(c.resolve(t[d]),void 0,i,u);return l}}),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,u,c,l,p,d,f,g,m){"use strict";function y(t,e){R.async(t,e)}function v(){R.on.apply(R,arguments)}function S(){R.off.apply(R,arguments)}var E=t["default"],P=e["default"],w=i["default"],B=n["default"],b=r["default"],U=o["default"],J=s["default"],x=a["default"],C=h["default"],_=u["default"],R=c.config,k=c.configure,T=l["default"],N=p["default"],q=d["default"],F=f["default"],O=g["default"];if(R.async=O,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var L=window.__PROMISE_INSTRUMENTATION__;k("instrument",!0);for(var A in L)L.hasOwnProperty(A)&&v(A,L[A])}m.Promise=E,m.EventTarget=P,m.all=B,m.allSettled=b,m.race=U,m.hash=J,m.hashSettled=x,m.rethrow=C,m.defer=_,m.denodeify=w,m.configure=k,m.on=v,m.off=S,m.resolve=N,m.reject=q,m.async=y,m.map=T,m.filter=F}),t.RSVP=i("rsvp")}(self),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.Queue=function(t){this._q=[],this.context=t,this.tick=EPUBJS.core.requestAnimationFrame,this.running=!1},EPUBJS.Queue.prototype.enqueue=function(){var t,e,i,n=[].shift.call(arguments),r=arguments;return"function"==typeof n?(t=new RSVP.defer,e=t.promise,i={task:n,args:r,deferred:t,promise:e}):i={promise:n},this._q.push(i),i.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e;return this._q.length?(t=this._q.shift(),e=t.task,e?e.apply(this.context,t.args).then(function(){t.deferred.resolve.apply(t.context||this.context,arguments)}.bind(this)):t.promise):(t=new RSVP.defer,t.deferred.resolve(),t.promise)},EPUBJS.Queue.prototype.flush=function(){for(;this._q.length;)this.dequeue()},EPUBJS.Queue.prototype.run=function(){!this.running&&this._q.length&&(this.running=!0,this.dequeue().then(function(){this.running=!1}.bind(this))),this.tick.call(window,this.run.bind(this))},EPUBJS.Queue.prototype.clear=function(){this._q=[]},EPUBJS.Queue.prototype.length=function(){return this._q.length},EPUBJS.Task=function(t){return function(){var e=arguments||[];return new RSVP.Promise(function(i){var n=function(t){i(t)};e.push(n),t.apply(this,e)}.bind(this))}},EPUBJS.Hook=function(t){this.context=t||this,this.hooks=[]},EPUBJS.Hook.prototype.register=function(t){this.hooks.push(t)},EPUBJS.Hook.prototype.trigger=function(){var t,e=this.hooks.length,i=0,n=new RSVP.defer,r=arguments;return e?(t=this.hooks[i].apply(this.context,r),t.then(function(){return i+=1,e>i?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}):void console.error("No RootFile Found"):void console.error("Container File Not Found")},EPUBJS.Parser.prototype.identifier=function(t){var e;return t?(e=t.querySelector("metadata"),e?this.getElementText(e,"identifier"):void console.error("No Metadata Found")):void console.error("Package File Not Found")},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}):void console.error("No Spine Found"):void console.error("No Manifest Found"):void console.error("No Metadata Found"):void console.error("Package File Not Found")},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);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)||c.steps.push(u%2===0?l(h):{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})},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()},EPUBJS.View.prototype.expand=function(){var t=this.lockedWidth,e=this.lockedHeight;t&&!e&&(e=this.document.documentElement.scrollHeight),e&&!t&&(t=this.document.body.scrollWidth),this.resize(t,e)},EPUBJS.View.prototype.mediaQueryListeners=function(){for(var t=this.document.styleSheets,e=function(t){t.matches&&this.expand()}.bind(this),i=0;i=0?i:u%2===0?u:u-1;return r=s>1?Math.floor((h-c)/s):h,o=(r+c)*s,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=h,this.height=e,this.spread=o,this.column=r,this.gap=c,this.divisor=s,this},EPUBJS.Layout.Reflowable.prototype.format=function(t){var e=t.document.documentElement,i=t.document.body;e.style.overflow="hidden",i.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.documentElement.scrollWidth,i=Math.ceil(e/this.spreadWidth);return{spreads:i,pages:i*this.divisor}},EPUBJS.Layout.Fixed=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.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:!1,layoutOveride:null}),EPUBJS.core.extend(this.settings,e),this.viewSettings={},this.book=t,this.settings.hidden&&(this.wrapper=this.wrap(this.container)),this.views=[],this.hooks={},this.hooks.layout=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(EPUBJS.replace.links.bind(this)),this.q=new EPUBJS.Queue(this),this.q.enqueue(this.book.opened),this.book.opened.then(function(){this.globalLayoutProperties=this.parseLayoutProperties(this.book.package.metadata)}.bind(this))},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.element.appendChild(this.container),this.attachListeners(),this.stageSize(),this.layoutMethod(),this.trigger("attached"),void this.q.run()):void console.error("Not an Element")},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(function(t){var e,i=new RSVP.defer,n=i.promise,r=this.book.spine.get(t);return this.displaying=!0,r?(e=this.createView(r),this.q.enqueue(this.append,e),i.resolve(this)):i.reject(new Error("No Section Found")),n},t)},EPUBJS.Rendition.prototype.moveTo=function(){},EPUBJS.Rendition.prototype.render=function(t){return t.create(),t.onLayout=this.layout.format.bind(this.layout),this.resizeView(t),t.display(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.show()}.bind(this)).then(function(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.onShown=this.afterDisplayed.bind(this),this.render(t)},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){this.remove(t)}.bind(this))},EPUBJS.Rendition.prototype.remove=function(t){var e=this.views.indexOf(t);e>-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.resizeView=function(t){"pre-paginated"===this.globalLayoutProperties.layout?t.lock(this.stage.width,this.stage.height):t.lock(this.stage.width,null)},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},EPUBJS.Rendition.prototype.resize=function(t,e){this.stageSize(t,e),this.layoutMethod(),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=this.layoutOveride&&this.layoutOveride.layout||t.layout||"reflowable",i=this.layoutOveride&&this.layoutOveride.spread||t.spread||"auto",n=this.layoutOveride&&this.layoutOveride.orientation||t.orientation||"auto";return{layout:e,spread:i,orientation:n}},RSVP.EventTarget.mixin(EPUBJS.Rendition.prototype),EPUBJS.Continuous=function(t,e){EPUBJS.Rendition.apply(this,arguments),this.settings=EPUBJS.core.extend(this.settings||{},{infinite:!0,hidden:!1,width:!1,height:!1,overflow:"auto",axis:"vertical",offset:500,offsetDelta:100}),EPUBJS.core.extend(this.settings,e),this.settings.hidden&&(this.wrapper=this.wrap(this.container))},EPUBJS.Continuous.prototype=Object.create(EPUBJS.Rendition.prototype),EPUBJS.Continuous.prototype.constructor=EPUBJS.Continuous,EPUBJS.Continuous.prototype.attachListeners=function(){EPUBJS.core.isNumber(this.settings.width)&&EPUBJS.core.isNumber(this.settings.height)||window.addEventListener("resize",this.onResized.bind(this),!1),this.settings.infinite&&this.start()},EPUBJS.Continuous.prototype.display=function(t){return this.q.enqueue(function(t){var e,i=new RSVP.defer,n=i.promise,r=this.book.spine.get(t);return this.displaying=!0,r?(e=new EPUBJS.View(r,this.viewSettings),this.q.enqueue(this.fill,e),this.q.enqueue(this.check),i.resolve(this)):i.reject(new Error("No Section Found")),n},t)},EPUBJS.Continuous.prototype.moveTo=function(){},EPUBJS.Continuous.prototype.afterDisplayed=function(t){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(i=new EPUBJS.View(n,this.viewSettings),this.q.enqueue(this.append,i)),0===o&&r&&(e=new EPUBJS.View(r,this.viewSettings),this.q.enqueue(this.prepend,e)),t.onShown=this.afterDisplayed.bind(this),this.trigger("displayed",t.section)},EPUBJS.Continuous.prototype.removeShownListeners=function(t){t.onShown=function(){}},EPUBJS.Continuous.prototype.append=function(t){return this.views.push(t),this.container.appendChild(t.element),t.onShown=this.afterDisplayed.bind(this),this.check()},EPUBJS.Continuous.prototype.prepend=function(t){return this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onShown=this.afterDisplayed.bind(this),t.on("resized",this.counter.bind(this)),this.check()},EPUBJS.Continuous.prototype.counter=function(t){"vertical"===this.settings.axis?this.scrollBy(0,t.heightDelta,!0):this.scrollBy(t.widthDelta,0,!0)},EPUBJS.Continuous.prototype.fill=function(t){return this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onShown=this.afterDisplayed.bind(this),this.render(t)},EPUBJS.Continuous.prototype.insert=function(t,e){return this.views.splice(e,0,t),e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.off("resized"),t.shown&&t.destroy(),t=null},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.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();return"horizontal"===this.settings.axis&&i.right>=n.left-this.settings.offset&&!(i.left>=n.right+this.settings.offset)?!0:"vertical"===this.settings.axis&&i.bottom>=n.top-this.settings.offset&&!(i.top>=n.bottom+this.settings.offset)?!0:!1},EPUBJS.Continuous.prototype.check=function(){var t,e=new RSVP.defer;return t=this.settings.height?this.container.getBoundingClientRect():EPUBJS.core.windowBounds(),this.views.forEach(function(e){var i=this.isVisible(e,t);i?e.shown||this.rendering||this.q.enqueue(function(){return this.render(e).then(function(){this.q.enqueue(this.check)}.bind(this))}):e.shown&&e.destroy()}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.q.enqueue(this.trim)}.bind(this),250),e.resolve(),e.promise},EPUBJS.Continuous.prototype.trim=function(){var t=new RSVP.defer,e=!0;return this.views.forEach(function(t,i){var n=i>0?this.views[i-1].shown:!1,r=i+1=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?(this.container.scrollLeft+=t,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(null,this.stage.height):t.lock(this.stage.width,null)},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().width