1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-02 14:49:16 +02:00
epub.js/dist/epub.min.js
2015-06-05 09:12:54 -04:00

3 lines
No EOL
70 KiB
JavaScript

"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){w.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?w.instrument&&B("fulfilled",t):w.async(g,t))}function d(t,e){t._state===b&&(t._state=J,t._result=e,w.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&&w.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(w.instrument&&B(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;s<e.length;s+=3)n=e[s],r=e[s+i],n?v(i,n,r,o):r(o);t._subscribers.length=0}}function y(){this.error=null}function m(t,e){try{return t(e)}catch(i){return R.error=i,R}}function v(t,e,i,n){var r,o,s,a,h=P(i);if(h){if(r=m(i,n),r===R?(a=!0,o=r.error,r=null):s=!0,e===r)return void d(e,new TypeError("A promises callback cannot return that same promise."))}else r=n,s=!0;e._state!==b||(h&&s?c(e,r):a?d(e,o):t===U?p(e,r):t===J&&d(e,r))}function S(t,e){try{e(function(e){c(t,e)},function(e){d(t,e)})}catch(i){d(t,i)}}var E=t.objectOrFunction,P=t.isFunction,B=(t.now,e["default"]),w=i.config,b=void 0,U=1,J=2,x=new y,R=new y;n.noop=r,n.resolve=c,n.reject=d,n.fulfill=p,n.subscribe=f,n.publish=g,n.publishRejection=l,n.initializePromise=S,n.invokeCallback=v,n.FULFILLED=U,n.REJECTED=J}),e("rsvp/all-settled",["./enumerator","./promise","./utils","exports"],function(t,e,i,n){"use strict";function r(t,e,i){this._superConstructor(t,e,!1,i)}var o=t["default"],s=t.makeSettledResult,a=e["default"],h=i.o_create;r.prototype=h(o.prototype),r.prototype._superConstructor=o,r.prototype._makeResult=s,r.prototype._validationError=function(){return new Error("allSettled must be called with an array")},n["default"]=function(t,e){return new r(a,t,e).promise}}),e("rsvp/all",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.all(t,e)}}),e("rsvp/asap",["exports"],function(t){"use strict";function e(){return function(){process.nextTick(o)}}function i(){var t=0,e=new u(o),i=document.createTextNode("");return e.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}function n(){var t=new MessageChannel;return t.port1.onmessage=o,function(){t.port2.postMessage(0)}}function r(){return function(){setTimeout(o,1)}}function o(){for(var t=0;s>t;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;s<n.length;s++)(r=n[s])(e)}}}),e("rsvp/filter",["./promise","./utils","exports"],function(t,e,i){"use strict";{var n=t["default"],r=e.isFunction;e.isMaybeThenable}i["default"]=function(t,e,i){return n.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as filter's second argument.");for(var o=t.length,s=new Array(o),a=0;o>a;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;e<o.length;e++)t=o[e],n.trigger(t.name,t.payload);o.length=0},50)}}),e("rsvp/map",["./promise","./utils","exports"],function(t,e,i){"use strict";var n=t["default"],r=(e.isArray,e.isFunction);i["default"]=function(t,e,i){return n.all(t,i).then(function(t){if(!r(e))throw new TypeError("You must pass a function as map's second argument.");for(var o=t.length,s=new Array(o),a=0;o>a;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;l<e.length;l++)c=e[l],p[c]=d[l];n(p)}else n(u)}i.push(a),t.apply(h,i)}return new n(r)})}var o=e===!0,s=r(e);return i.__proto__=t,i}}),e("rsvp/promise-hash",["./enumerator","./-internal","./utils","exports"],function(t,e,i,n){"use strict";function r(t,e,i){this._superConstructor(t,e,!0,i)}var o=t["default"],s=e.PENDING,a=(e.FULFILLED,i.o_create);n["default"]=r,r.prototype=a(o.prototype),r.prototype._superConstructor=o,r.prototype._init=function(){this._result={}},r.prototype._validateInput=function(t){return t&&"object"==typeof t},r.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},r.prototype._enumerate=function(){var t=this.promise,e=this._input,i=[];for(var n in e)t._state===s&&e.hasOwnProperty(n)&&i.push({position:n,entry:e[n]});var r=i.length;this._remaining=r;for(var o,a=0;t._state===s&&r>a;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=C++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),v!==t&&(y(t)||l(),this instanceof d||p(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),y=(n.objectOrFunction,n.isFunction),m=n.now,v=r.noop,S=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,P=r.invokeCallback,B=r.FULFILLED,w=o["default"],b=s["default"],U=a["default"],J=h["default"],x=u["default"],R="rsvp_"+m()+"-",C=0;c["default"]=d,d.cast=w,d.all=b,d.race=U,d.resolve=J,d.reject=x,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,i){var n=this;n._onerror=null;var r=new this.constructor(v,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===B&&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,y){"use strict";function m(t,e){T.async(t,e)}function v(){T.on.apply(T,arguments)}function S(){T.off.apply(T,arguments)}var E=t["default"],P=e["default"],B=i["default"],w=n["default"],b=r["default"],U=o["default"],J=s["default"],x=a["default"],R=h["default"],C=u["default"],T=c.config,_=c.configure,k=l["default"],N=p["default"],F=d["default"],q=f["default"],L=g["default"];if(T.async=L,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var O=window.__PROMISE_INSTRUMENTATION__;_("instrument",!0);for(var I in O)O.hasOwnProperty(I)&&v(I,O[I])}y.Promise=E,y.EventTarget=P,y.all=w,y.allSettled=b,y.race=U,y.hash=J,y.hashSettled=x,y.rethrow=R,y.defer=C,y.denodeify=B,y.configure=_,y.on=v,y.off=S,y.resolve=N,y.reject=F,y.async=m,y.map=k,y.filter=q}),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);++e<n;)r[e]=t[i[e]];return r},EPUBJS.core.resolveUrl=function(t,e){var i,n=[],r=[],o=EPUBJS.core.uri(t),s=EPUBJS.core.uri(e),a=o.directory,h=s.directory,u=[];return"/"===a[0]&&(a=a.substring(1)),"/"===h[h.length-1]&&(a=a.substring(0,a.length-1)),"/"===h[0]&&(h=h.substring(1)),"/"===h[h.length-1]&&(h=h.substring(0,h.length-1)),a&&(u=a.split("/")),i=h.split("/"),i.reverse().forEach(function(t){".."===t?u.pop():t===u[u.length-1]?(u.pop(),r.unshift(t)):r.unshift(t)}),n=[o.origin],u.length&&(n=n.concat(u)),r&&(n=n.concat(r)),n=n.concat(s.filename),n.join("/")},EPUBJS.core.documentHeight=function(){return Math.max(document.documentElement.clientHeight,document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight)},EPUBJS.core.isNumber=function(t){return!isNaN(parseFloat(t))&&isFinite(t)},EPUBJS.core.prefixed=function(t){var e=["Webkit","Moz","O","ms"],i=t[0].toUpperCase()+t.slice(1),n=e.length;if("undefined"!=typeof document.body.style[t])return t;for(var r=0;n>r;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;o<n.length&&(e=n[o],e.nodeType===Node.TEXT_NODE&&r++,e!=t);o++);return 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),setTimeout(this.flush.bind(this),0),i.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e,i;return this._q.length?(t=this._q.shift(),(e=t.task)?(i=e.apply(this.context,t.args),i&&"function"==typeof i.then?i.then(function(){t.deferred.resolve.apply(this.context,arguments)}.bind(this)):(t.deferred.resolve.apply(this.context,i),t.promise)):t.promise?t.promise:void 0):(t=new RSVP.defer,t.deferred.resolve(),t.promise)},EPUBJS.Queue.prototype.dump=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.flush=function(){return this.running?this.running:this._q.length?(this.running=this.dequeue().then(function(){return this.running=void 0,this.flush()}.bind(this)),this.running):void 0},EPUBJS.Queue.prototype.clear=function(){this._q=[],this.running=!1},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);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)||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.spinePos<e.spinePos)return-1;for(var i=0;i<t.steps.length;i++){if(!e.steps[i])return 1;if(t.steps[i].index>e.steps[i].index)return 1;if(t.steps[i].index<e.steps[i].index)return-1}return t.steps.length<e.steps.length?-1:t.characterOffset>e.characterOffset?1:t.characterOffset<e.characterOffset?-1:0
},EPUBJS.EpubCFI.prototype.generateCfiFromHref=function(t,e){var i,n,r=EPUBJS.core.uri(t),o=r.path,s=r.fragment,a=e.spineIndexByURL[o],h=new RSVP.defer,u=new EPUBJS.EpubCFI;return"undefined"!=typeof a&&(n=e.spine[a],i=e.loadXml(n.url),i.then(function(t){var e,i=t.getElementById(s);e=u.generateCfiFromElement(i,n.cfiBase),h.resolve(e)})),h.promise},EPUBJS.EpubCFI.prototype.generateCfiFromTextNode=function(t,e,i){var n=t.parentNode,r=this.pathTo(n),o=this.generatePathComponent(r),s=1+2*Array.prototype.indexOf.call(n.childNodes,t);return"epubcfi("+i+"!"+o+"/"+s+":"+(e||0)+")"},EPUBJS.EpubCFI.prototype.generateCfiFromRangeAnchor=function(t,e){var i=t.anchorNode,n=t.anchorOffset;return this.generateCfiFromTextNode(i,n,e)},EPUBJS.EpubCFI.prototype.generateCfiFromRange=function(t,e){var i,n,r,o,s,a,h,u,c,l,p,d;if(i=t.startContainer,3===i.nodeType)n=i.parentNode,a=1+2*EPUBJS.core.indexOfTextNode(i),r=this.pathTo(n);else{if(t.collapsed)return this.generateCfiFromElement(i,e);r=this.pathTo(i)}return o=this.generatePathComponent(r),s=t.startOffset,t.collapsed?"epubcfi("+e+"!"+o+"/"+a+":"+s+")":(h=t.endContainer,3===h.nodeType?(u=h.parentNode,d=1+2*EPUBJS.core.indexOfTextNode(h),c=this.pathTo(u)):c=this.pathTo(h),l=this.generatePathComponent(c),p=t.endOffset,"epubcfi("+e+"!"+o+"/"+a+":"+s+","+l+"/"+d+":"+p+")")},EPUBJS.EpubCFI.prototype.generateXpathFromSteps=function(t){var e=[".","*"];return t.forEach(function(t){var i=t.index+1;e.push(t.id?"*[position()="+i+" and @id='"+t.id+"']":"text"===t.type?"text()["+i+"]":"*["+i+"]")}),e.join("/")},EPUBJS.EpubCFI.prototype.generateRangeFromCfi=function(t,e){var i,n,r,o,s=e||document,a=s.createRange();return"string"==typeof t&&(t=this.parse(t)),-1===t.spinePos?!1:(n=this.generateXpathFromSteps(t.steps),i=t.steps[t.steps.length-1],(r=s.evaluate(n,s,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue)?(r&&t.characterOffset>=0?(o=r.length,t.characterOffset<o?(a.setStart(r,t.characterOffset),a.setEnd(r,o)):(console.debug("offset greater than length:",t.characterOffset,o),a.setStart(r,o-1),a.setEnd(r,o))):r&&a.selectNode(r),a):null)},EPUBJS.Navigation=function(t,e){var i=this,n=new EPUBJS.Parser,r=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.navUrl,"xml").then(function(e){i.toc=n.nav(e),i.loaded(i.toc),t.resolve(i.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.ncxUrl,"xml").then(function(e){i.toc=n.ncx(e),i.loaded(i.toc),t.resolve(i.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,i;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(i=new RSVP.defer,i.resolve([]),e=i.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,i=0;i<t.length;i++)e=t[i],this.tocByHref[e.href]=i,this.tocById[e.id]=i},EPUBJS.Navigation.prototype.get=function(t){var e;return t?(0===t.indexOf("#")?e=this.tocById[t.substring(1)]:t in this.tocByHref&&(e=this.tocByHref[t]),this.toc[e]):this.toc},EPUBJS.Section=function(t){this.idref=t.idref,this.linear=t.linear,this.properties=t.properties,this.index=t.index,this.href=t.href,this.url=t.url,this.next=t.next,this.prev=t.prev,this.epubcfi=new EPUBJS.EpubCFI,this.cfiBase=t.cfiBase,this.hooks={},this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(this.replacements)},EPUBJS.Section.prototype.load=function(t){var e=t||this.request||EPUBJS.core.request,i=new RSVP.defer,n=i.promise;return this.contents?i.resolve(this.contents):e(this.url,"xml").then(function(t){EPUBJS.core.folder(this.url);return this.document=t,this.contents=t.documentElement,this.hooks.replacements.trigger(this.document)}.bind(this)).then(function(){i.resolve(this.contents)}.bind(this)).catch(function(t){i.reject(t)}),n},EPUBJS.Section.prototype.replacements=function(t){var e,i=new RSVP.defer,n=t.createElement("base");return n.setAttribute("href",this.url),t&&(e=t.querySelector("head")),e?(e.insertBefore(n,e.firstChild),i.resolve()):i.reject(new Error("No head to insert into")),i.promise},EPUBJS.Section.prototype.beforeSectionLoad=function(){},EPUBJS.Section.prototype.render=function(t){var e=new RSVP.defer,i=e.promise;return this.load(t).then(function(t){var i=new XMLSerializer,n=i.serializeToString(t);e.resolve(n)}).catch(function(t){e.reject(t)}),i},EPUBJS.Section.prototype.find=function(){},EPUBJS.Section.prototype.reconcileLayoutSettings=function(t){var e={layout:t.layout,spread:t.spread,orientation:t.orientation};return this.properties.forEach(function(t){var i,n,r=t.replace("rendition:",""),o=r.indexOf("-");-1!=o&&(i=r.slice(0,o),n=r.slice(o+1),e[i]=n)}),e},EPUBJS.Section.prototype.cfiFromRange=function(t){return this.epubcfi.generateCfiFromRange(t,this.cfiBase)},EPUBJS.Spine=function(t){this.request=t,this.spineItems=[],this.spineByHref={},this.spineById={}},EPUBJS.Spine.prototype.load=function(t){this.items=t.spine,this.manifest=t.manifest,this.spineNodeIndex=t.spineNodeIndex,this.baseUrl=t.baseUrl||"",this.length=this.items.length,this.epubcfi=new EPUBJS.EpubCFI,this.items.forEach(function(t,e){var i,n=this.manifest[t.idref];t.cfiBase=this.epubcfi.generateChapterComponent(this.spineNodeIndex,t.index,t.idref),n&&(t.href=n.href,t.url=this.baseUrl+t.href,n.properties.length&&t.properties.push.apply(t.properties,n.properties)),t.prev=function(){return this.get(e-1)}.bind(this),t.next=function(){return this.get(e+1)}.bind(this),i=new EPUBJS.Section(t),this.append(i)}.bind(this))},EPUBJS.Spine.prototype.get=function(t){var e=0;return"string"==typeof t&&0===t.indexOf("epubcfi(")&&(cfi=new EPUBJS.EpubCFI(t),e=cfi.spinePos),!t||"number"!=typeof t&&isNaN(t)!==!1?t&&0===t.indexOf("#")?e=this.spineById[t.substring(1)]:t&&(t=t.split("#")[0],e=this.spineByHref[t]):e=t,this.spineItems[e]||null},EPUBJS.Spine.prototype.append=function(t){var e=this.spineItems.length;return t.index=e,this.spineItems.push(t),this.spineByHref[t.href]=e,this.spineById[t.idref]=e,e},EPUBJS.Spine.prototype.prepend=function(t){this.spineItems.unshift(t);return this.spineByHref[t.href]=0,this.spineById[t.idref]=0,this.spineItems.forEach(function(t,e){t.index=e}),0},EPUBJS.Spine.prototype.insert=function(){},EPUBJS.Spine.prototype.remove=function(t){var e=this.spineItems.indexOf(t);return e>-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<n.length;o++)r(n[o]);return i.resolve(),i.promise},EPUBJS.Book=function(t){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,e.directory)):this.url=e.directory,i=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+s,i=this.request(this.containerUrl).then(function(t){return r.container(t)}).then(function(e){var i=EPUBJS.core.uri(e.packagePath);return o.packageUrl=t+e.packagePath,o.encoding=e.encoding,i.origin?o.url=i.base:window?(n=EPUBJS.core.uri(window.location.href),o.url=EPUBJS.core.resolveUrl(n.base,t+i.directory)):o.url=i.directory,o.request(o.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(t)})),i.then(function(t){o.unpack(t),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(t){console.error(t.message,t.stack),o.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,i=new EPUBJS.Parser;e.package=i.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){var i=e&&e.method?e.method.charAt(0).toUpperCase()+e.method.substr(1):"Rendition";return this.rendition=new EPUBJS[i](this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.View=function(t,e){this.settings=e||{},this.id="epubjs-view:"+EPUBJS.core.uuid(),this.section=t,this.index=t.index,this.element=document.createElement("div"),this.element.classList.add("epub-view"),this.element.style.height="0px",this.element.style.width="0px",this.element.style.overflow="hidden",this.displayed=!1,this.rendered=!1,this.epubcfi=new EPUBJS.EpubCFI,this.element.style.display=this.settings.axis&&"horizontal"==this.settings.axis?"inline-block":"block"},EPUBJS.View.prototype.create=function(){return this.iframe?this.iframe:(this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.element.appendChild(this.iframe),this.rendered=!0,this.elementBounds=EPUBJS.core.bounds(this.element),this.supportsSrcdoc=!1,this.iframe)},EPUBJS.View.prototype.lock=function(t,e){var i,n=EPUBJS.core.borders(this.element);i=this.iframe?EPUBJS.core.borders(this.iframe):{width:0,height:0},EPUBJS.core.isNumber(t)&&(this.lockedWidth=t-n.width-i.width,this.resize(this.lockedWidth,t)),EPUBJS.core.isNumber(e)&&(this.lockedHeight=e-n.height-i.height,this.resize(null,this.lockedHeight)),EPUBJS.core.isNumber(t)&&EPUBJS.core.isNumber(e)&&(this.lockedWidth=t-n.width-i.width,this.lockedHeight=e-n.height-i.height,this.resize(this.lockedWidth,this.lockedHeight)),this.displayed&&this.iframe&&(this.layout(),this.expand())},EPUBJS.View.prototype.resize=function(t,e){this.iframe&&(EPUBJS.core.isNumber(t)&&(this.iframe.style.width=t+"px"),EPUBJS.core.isNumber(e)&&(this.iframe.style.height=e+"px"),this.iframeBounds=EPUBJS.core.bounds(this.iframe),this.reframe(this.iframeBounds.width,this.iframeBounds.height))},EPUBJS.View.prototype.reframe=function(t,e){this.displayed&&(EPUBJS.core.isNumber(t)&&(this.element.style.width=t+"px"),EPUBJS.core.isNumber(e)&&(this.element.style.height=e+"px"),this.prevBounds=this.elementBounds,this.elementBounds=EPUBJS.core.bounds(this.element),this.trigger("resized",{width:this.elementBounds.width,height:this.elementBounds.height,widthDelta:this.elementBounds.width-this.prevBounds.width,heightDelta:this.elementBounds.height-this.prevBounds.height}))},EPUBJS.View.prototype.resized=function(){},EPUBJS.View.prototype.render=function(t){return this.rendering=!0,this.section.render(t).then(function(t){return this.load(t)}.bind(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,i=e.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,this.rendering=!1,e.resolve(this)}.bind(this)),this.supportsSrcdoc?this.iframe.srcdoc=t:(this.document.open(),this.document.write(t),this.document.close()),i):(e.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.layout=function(t){this.iframe.style.display="inline-block",this.document.body.style.margin="0",t&&t(this),this.onLayout(this)},EPUBJS.View.prototype.onLayout=function(){},EPUBJS.View.prototype.listeners=function(){this.section.properties.indexOf("scripted")>-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,this.resize(null,e)),e&&!t&&(t=this.document.body.scrollWidth,this.resize(t,null))},EPUBJS.View.prototype.mediaQueryListeners=function(){for(var t=this.document.styleSheets,e=function(t){t.matches&&this.expand()}.bind(this),i=0;i<t.length;i+=1)for(var n=t[i].cssRules,r=0;r<n.length;r+=1)if(n[r].media){var o=this.window.matchMedia(n[r].media.mediaText);o.addListener(e)}},EPUBJS.View.prototype.observe=function(t){var e=this,i=new MutationObserver(function(){e.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(t,n),i},EPUBJS.View.prototype.imageLoadListeners=function(){for(var t,e=this.document.body.querySelectorAll("img"),i=0;i<e.length;i++)t=e[i],"undefined"!=typeof t.naturalWidth&&0===t.naturalWidth&&(t.onload=this.expand.bind(this))},EPUBJS.View.prototype.display=function(){var t=new RSVP.defer;return this.displayed=!0,this.layout(),this.listeners(),this.expand(),this.trigger("displayed",this),this.onDisplayed(this),t.resolve(this),t.promise},EPUBJS.View.prototype.show=function(){this.element.style.visibility="visible",this.iframe&&(this.iframe.style.visibility="visible"),this.trigger("shown",this)},EPUBJS.View.prototype.hide=function(){this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.stopExpanding=!0,this.trigger("hidden",this)},EPUBJS.View.prototype.position=function(){return this.element.getBoundingClientRect()},EPUBJS.View.prototype.onDisplayed=function(){},EPUBJS.View.prototype.bounds=function(){return this.elementBounds||(this.elementBounds=EPUBJS.core.bounds(this.element)),this.elementBounds},EPUBJS.View.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.displayed&&(this.stopExpanding=!0,this.element.removeChild(this.iframe),this.displayed=!1,this.iframe=null)},EPUBJS.View.prototype.root=function(){return this.document?this.document.documentElement:null},EPUBJS.View.prototype.locationOf=function(t){if(this.document){if(0===t.indexOf("epubcfi(")){if(cfi=this.epubcfi.parse(t),"undefined"==typeof document.evaluate){if(marker=this.epubcfi.addMarker(cfi,this.document))return this.epubcfi.removeMarker(marker,this.document),marker.getBoundingClientRect()}else if(range=this.epubcfi.generateRangeFromCfi(cfi,this.document))return range.getBoundingClientRect()}else if(t.indexOf("#")>-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",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.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.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(),void this.trigger("attached")):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(this._display,t)},EPUBJS.Rendition.prototype._display=function(t){var e,i,n,r,o=new RSVP.defer,s=o.promise;return"string"==typeof t&&0===t.indexOf("epubcfi(")?(n=new EPUBJS.EpubCFI(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(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,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<this.views.length;r++)e=this.views[r],t=this.isVisible(e,0,0,i),t===!0&&n.push(e);return n},EPUBJS.Rendition.prototype.bounds=function(){var t;return t=this.settings.height?this.container.getBoundingClientRect():EPUBJS.core.windowBounds()},EPUBJS.Rendition.prototype.displayed=function(){for(var t,e=[],i=0;i<this.views.length;i++)t=this.views[i],t.displayed&&e.push(t);return e},EPUBJS.Rendition.prototype.show=function(){for(var t,e=0;e<this.views.length;e++)t=this.views[e],t.displayed&&t.show();this.hidden=!1},EPUBJS.Rendition.prototype.hide=function(){for(var t,e=0;e<this.views.length;e++)t=this.views[e],t.displayed&&t.hide();this.hidden=!0},EPUBJS.Rendition.prototype.destroy=function(){this.q.clear(),this.clear(),clearTimeout(this.trimTimeout),this.element.removeChild(this.settings.hidden?this.wrapper:this.container)},EPUBJS.Rendition.prototype.reportLocation=function(){return this.q.enqueue(function(){this.location=this.currentLocation(),this.trigger("locationChanged",this.location)}.bind(this))},EPUBJS.Rendition.prototype.currentLocation=function(){var t;return this.views.length?(t=this.views[0],this.map.page(t)):void 0},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,overflow:"auto",axis:"vertical",offset:500,offsetDelta:250}),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){var e,i,n,r,o=new RSVP.defer,s=o.promise;return"string"==typeof t&&0===t.indexOf("epubcfi(")?(n=new EPUBJS.EpubCFI(t),r=n.spinePos,e=this.book.spine.get(r)):e=this.book.spine.get(t),this.displaying=!0,this.hide(),e?(i=new EPUBJS.View(e,this.viewSettings),this.q.enqueue(this.fill,i).then(function(){this.q.enqueue(function(){var e=i.locationOf(t);return this.moveTo(e)}),this.q.enqueue(this.check),this.q.enqueue(this.show),this.hooks.display.trigger(i)}.bind(this)),o.resolve(this)):o.reject(new Error("No Section Found")),s},EPUBJS.Continuous.prototype.moveTo=function(t){var e=this.bounds(),i=Math.floor(t.top/e.height)*e.height;return this.check(0,i+this.settings.offset).then(function(){"vertical"===this.settings.axis?this.scrollBy(0,i):this.scrollBy(i,0)}.bind(this))},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)),this.trigger("displayed",t.section)},EPUBJS.Continuous.prototype.removeShownListeners=function(t){t.onDisplayed=function(){}},EPUBJS.Continuous.prototype.append=function(t){return this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=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.onDisplayed=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.onDisplayed=this.afterDisplayed.bind(this),this.render(t).then(function(){return this.check()}.bind(this))},EPUBJS.Continuous.prototype.insert=function(t,e){return this.views.splice(e,0,t),e<this.cotainer.children.length?this.container.insertBefore(t.element,this.container.children[e]):this.container.appendChild(t.element),this.check()},EPUBJS.Continuous.prototype.first=function(){return this.views[0]},EPUBJS.Continuous.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Continuous.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Continuous.prototype.check=function(t){var e=new RSVP.defer,i=this.bounds(),n=[],r=t||this.settings.offset;return this.views.forEach(function(t){var e=this.isVisible(t,r,r,i);e?t.displayed||t.rendering||n.push(this.render(t)):t.displayed&&this.q.enqueue(t.destroy.bind(t))}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.q.enqueue(this.trim)}.bind(this),250),n.length?RSVP.all(n).then(function(){this.q.enqueue(this.check)}.bind(this)):(e.resolve(),e.promise)},EPUBJS.Continuous.prototype.trim=function(){for(var t=new RSVP.defer,e=this.displayed(),i=e[0],n=e[e.length-1],r=this.views.indexOf(i),o=this.views.indexOf(n),s=this.views.slice(0,r),a=this.views.slice(o+1),h=0;h<s.length-1;h++)this.erase(s[h],s);for(var h=1;h<a.length;h++)this.erase(a[h]);return t.resolve(),t.promise},EPUBJS.Continuous.prototype.erase=function(t,e){var i,n;this.settings.height?(i=this.container.scrollTop,n=this.container.scrollLeft):(i=window.scrollY,n=window.scrollX);var r=t.bounds();this.remove(t),e&&("vertical"===this.settings.axis?this.scrollTo(0,i-r.height,!0):this.scrollTo(n-r.width,0,!0))},EPUBJS.Continuous.prototype.checkCurrent=function(){var t,e,i=this.container.getBoundingClientRect(),n=this.views.length-1;if(!this.rendering)if("horizontal"===this.settings.axis);else for(var r=n;r>=0;r--)if(t=this.views[r],e=t.bounds().top,e<i.bottom){if(this.current==t.section)break;this.current=t.section,this.trigger("current",this.current);break}},EPUBJS.Continuous.prototype.start=function(){var t;this.tick=EPUBJS.core.requestAnimationFrame,this.settings.height?(this.prevScrollTop=this.container.scrollTop,this.prevScrollLeft=this.container.scrollLeft):(this.prevScrollTop=window.scrollY,this.prevScrollLeft=window.scrollX),this.scrollDeltaVert=0,this.scrollDeltaHorz=0,t=this.settings.height?this.container:window,window.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0,this.destroy()}.bind(this)),this.tick.call(window,this.onScroll.bind(this)),this.scrolled=!1},EPUBJS.Continuous.prototype.onScroll=function(){this.scrolled&&(this.settings.height?(scrollTop=this.container.scrollTop,scrollLeft=this.container.scrollLeft):(scrollTop=window.scrollY,scrollLeft=window.scrollX),this.ignore?this.ignore=!1:(0===this.scrollDeltaVert&&0===this.scrollDeltaHorz||this.scrollDeltaVert>this.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(null,this.stage.height):t.lock(this.stage.width,null)},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().width<t?1:2},EPUBJS.Paginate.prototype.forceSingle=function(t){this.isForcedSingle=t?!0:!1},EPUBJS.Paginate.prototype.determineLayout=function(t){var e=this.determineSpreads(this.settings.minSpreadWidth);console.log("spreads",e,this.settings.minSpreadWidth);var i=e?"ReflowableSpreads":"Reflowable",n=!1;return"pre-paginated"===t.layout&&(i="Fixed",n=!0,e=!1),"reflowable"===t.layout&&"none"===t.spread&&(i="Reflowable",n=!1,e=!1),"reflowable"===t.layout&&"both"===t.spread&&(i="ReflowableSpreads",n=!1,e=!0),this.spreads=e,i},EPUBJS.Paginate.prototype.start=function(){this.hooks.display.register(this.reportLocation),this.currentPage=0,window.addEventListener("unload",function(){this.ignore=!0,this.destroy()}.bind(this))},EPUBJS.Paginate.prototype.layoutMethod=function(){this.layout=new EPUBJS.Layout.Reflowable,this.layoutUpdate(),this.map=new EPUBJS.Map(this.layout)},EPUBJS.Paginate.prototype.layoutUpdate=function(){this.spreads=this.determineSpreads(this.settings.minSpreadWidth),this.layout.calculate(this.stage.width,this.stage.height,this.settings.gap,this.spreads),this.settings.offset=this.layout.delta},EPUBJS.Paginate.prototype.moveTo=function(t){var e=Math.floor(t.left/this.layout.delta)*this.layout.delta;return this.check(0,e+this.settings.offset).then(function(){this.scrollBy(e,0)}.bind(this))},EPUBJS.Paginate.prototype.page=function(){},EPUBJS.Paginate.prototype.next=function(){return this.q.enqueue(function(){return this.scrollBy(this.layout.delta,0),this.reportLocation(),this.check()})},EPUBJS.Paginate.prototype.prev=function(){return this.q.enqueue(function(){return this.scrollBy(-this.layout.delta,0),this.reportLocation(),this.check()})},EPUBJS.Paginate.prototype.reportLocation=function(){return this.q.enqueue(function(){this.location=this.currentLocation(),this.trigger("locationChanged",this.location)}.bind(this))},EPUBJS.Paginate.prototype.currentLocation=function(){var t,e,i,n,r,o,s=this.visible(),a=this.container.getBoundingClientRect();return 1===s.length?(t=a.left-s[0].position().left,i=t+this.layout.spread,this.map.page(s[0],t,i)):s.length>1?(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<r.pages;a++)e=(o+s)*a,i=o*(a+1)+s*a,n.push({start:this.findStart(t.document.body,e,i),end:this.findEnd(t.document.body,e,i)});return n},EPUBJS.Map.prototype.findStart=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 n,r,a,h;return t.nodeType==Node.TEXT_NODE?(h=document.createRange(),h.selectNodeContents(t),a=h.getBoundingClientRect()):a=t.getBoundingClientRect(),n=a.left,r=a.right,n>=e&&i>=n?t:r>e?t:(s=t,void o.push(t))}))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,void o.push(t))}))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<o.length;s++){if(n=o[s],r=n.getBoundingClientRect(),r.left>=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;a<s.length;a++){if(r=s[a],o=r.getBoundingClientRect(),o.left>i&&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<e.length;r++)i=this.rangePairToCfiPair(t.section,e[r]),n.push(i);return n};