mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
1 line
No EOL
41 KiB
JavaScript
1 line
No EOL
41 KiB
JavaScript
(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=i.toString,l=i.hasOwnProperty,c=r.forEach,h=r.map,p=r.reduce,d=r.reduceRight,v=r.filter,m=r.every,g=r.some,y=r.indexOf,b=r.lastIndexOf,w=Array.isArray,E=Object.keys,S=s.bind,x=function(e){return e instanceof x?e:this instanceof x?(this._wrapped=e,void 0):new x(e)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):e._=x,x.VERSION="1.4.4";var T=x.each=x.forEach=function(e,t,r){if(null!=e)if(c&&e.forEach===c)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;s>i;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(x.has(e,o)&&t.call(r,e[o],o,e)===n)return};x.map=x.collect=function(e,t,n){var r=[];return null==e?r:h&&e.map===h?e.map(t,n):(T(e,function(e,i,s){r[r.length]=t.call(n,e,i,s)}),r)};var N="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(e,t,n,r){var i=arguments.length>2;if(null==e&&(e=[]),p&&e.reduce===p)return r&&(t=x.bind(t,r)),i?e.reduce(t,n):e.reduce(t);if(T(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)}),!i)throw new TypeError(N);return n},x.reduceRight=x.foldr=function(e,t,n,r){var i=arguments.length>2;if(null==e&&(e=[]),d&&e.reduceRight===d)return r&&(t=x.bind(t,r)),i?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=x.keys(e);s=o.length}if(T(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)}),!i)throw new TypeError(N);return n},x.find=x.detect=function(e,t,n){var r;return C(e,function(e,i,s){return t.call(n,e,i,s)?(r=e,!0):void 0}),r},x.filter=x.select=function(e,t,n){var r=[];return null==e?r:v&&e.filter===v?e.filter(t,n):(T(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},x.reject=function(e,t,n){return x.filter(e,function(e,r,i){return!t.call(n,e,r,i)},n)},x.every=x.all=function(e,t,r){t||(t=x.identity);var i=!0;return null==e?i:m&&e.every===m?e.every(t,r):(T(e,function(e,s,o){return(i=i&&t.call(r,e,s,o))?void 0:n}),!!i)};var C=x.some=x.any=function(e,t,r){t||(t=x.identity);var i=!1;return null==e?i:g&&e.some===g?e.some(t,r):(T(e,function(e,s,o){return i||(i=t.call(r,e,s,o))?n:void 0}),!!i)};x.contains=x.include=function(e,t){return null==e?!1:y&&e.indexOf===y?e.indexOf(t)!=-1:C(e,function(e){return e===t})},x.invoke=function(e,t){var n=u.call(arguments,2),r=x.isFunction(t);return x.map(e,function(e){return(r?t:e[t]).apply(e,n)})},x.pluck=function(e,t){return x.map(e,function(e){return e[t]})},x.where=function(e,t,n){return x.isEmpty(t)?n?null:[]:x[n?"find":"filter"](e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},x.findWhere=function(e,t){return x.where(e,t,!0)},x.max=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&65535>e.length)return Math.max.apply(Math,e);if(!t&&x.isEmpty(e))return-1/0;var r={computed:-1/0,value:-1/0};return T(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},x.min=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&65535>e.length)return Math.min.apply(Math,e);if(!t&&x.isEmpty(e))return 1/0;var r={computed:1/0,value:1/0};return T(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;r.computed>o&&(r={value:e,computed:o})}),r.value},x.shuffle=function(e){var t,n=0,r=[];return T(e,function(e){t=x.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return x.isFunction(e)?e:function(t){return t[e]}};x.sortBy=function(e,t,n){var r=k(t);return x.pluck(x.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(r>n||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t||x.identity);return T(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};x.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(x.has(e,t)?e[t]:e[t]=[]).push(n)})},x.countBy=function(e,t,n){return L(e,t,n,function(e,t){x.has(e,t)||(e[t]=0),e[t]++})},x.sortedIndex=function(e,t,n,r){n=null==n?x.identity:k(n);for(var i=n.call(r,t),s=0,o=e.length;o>s;){var u=s+o>>>1;i>n.call(r,e[u])?s=u+1:o=u}return s},x.toArray=function(e){return e?x.isArray(e)?u.call(e):e.length===+e.length?x.map(e,x.identity):x.values(e):[]},x.size=function(e){return null==e?0:e.length===+e.length?e.length:x.keys(e).length},x.first=x.head=x.take=function(e,t,n){return null==e?void 0:null==t||n?e[0]:u.call(e,0,t)},x.initial=function(e,t,n){return u.call(e,0,e.length-(null==t||n?1:t))},x.last=function(e,t,n){return null==e?void 0:null==t||n?e[e.length-1]:u.call(e,Math.max(e.length-t,0))},x.rest=x.tail=x.drop=function(e,t,n){return u.call(e,null==t||n?1:t)},x.compact=function(e){return x.filter(e,x.identity)};var A=function(e,t,n){return T(e,function(e){x.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};x.flatten=function(e,t){return A(e,t,[])},x.without=function(e){return x.difference(e,u.call(arguments,1))},x.uniq=x.unique=function(e,t,n,r){x.isFunction(t)&&(r=n,n=t,t=!1);var i=n?x.map(e,n,r):e,s=[],o=[];return T(i,function(n,r){(t?r&&o[o.length-1]===n:x.contains(o,n))||(o.push(n),s.push(e[r]))}),s},x.union=function(){return x.uniq(a.apply(r,arguments))},x.intersection=function(e){var t=u.call(arguments,1);return x.filter(x.uniq(e),function(e){return x.every(t,function(t){return x.indexOf(t,e)>=0})})},x.difference=function(e){var t=a.apply(r,u.call(arguments,1));return x.filter(e,function(e){return!x.contains(t,e)})},x.zip=function(){for(var e=u.call(arguments),t=x.max(x.pluck(e,"length")),n=Array(t),r=0;t>r;r++)n[r]=x.pluck(e,""+r);return n},x.object=function(e,t){if(null==e)return{};for(var n={},r=0,i=e.length;i>r;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},x.indexOf=function(e,t,n){if(null==e)return-1;var r=0,i=e.length;if(n){if("number"!=typeof n)return r=x.sortedIndex(e,t),e[r]===t?r:-1;r=0>n?Math.max(0,i+n):n}if(y&&e.indexOf===y)return e.indexOf(t,n);for(;i>r;r++)if(e[r]===t)return r;return-1},x.lastIndexOf=function(e,t,n){if(null==e)return-1;var r=null!=n;if(b&&e.lastIndexOf===b)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);for(var i=r?n:e.length;i--;)if(e[i]===t)return i;return-1},x.range=function(e,t,n){1>=arguments.length&&(t=e||0,e=0),n=arguments[2]||1;for(var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=Array(r);r>i;)s[i++]=e,e+=n;return s},x.bind=function(e,t){if(e.bind===S&&S)return S.apply(e,u.call(arguments,1));var n=u.call(arguments,2);return function(){return e.apply(t,n.concat(u.call(arguments)))}},x.partial=function(e){var t=u.call(arguments,1);return function(){return e.apply(this,t.concat(u.call(arguments)))}},x.bindAll=function(e){var t=u.call(arguments,1);return 0===t.length&&(t=x.functions(e)),T(t,function(t){e[t]=x.bind(e[t],e)}),e},x.memoize=function(e,t){var n={};return t||(t=x.identity),function(){var r=t.apply(this,arguments);return x.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},x.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},x.defer=function(e){return x.delay.apply(x,[e,1].concat(u.call(arguments,1)))},x.throttle=function(e,t){var n,r,i,s,o=0,u=function(){o=new Date,i=null,s=e.apply(n,r)};return function(){var a=new Date,f=t-(a-o);return n=this,r=arguments,0>=f?(clearTimeout(i),i=null,o=a,s=e.apply(n,r)):i||(i=setTimeout(u,f)),s}},x.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},x.once=function(e){var t,n=!1;return function(){return n?t:(n=!0,t=e.apply(this,arguments),e=null,t)}},x.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},x.compose=function(){var e=arguments;return function(){for(var t=arguments,n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},x.after=function(e,t){return 0>=e?t():function(){return 1>--e?t.apply(this,arguments):void 0}},x.keys=E||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)x.has(e,n)&&(t[t.length]=n);return t},x.values=function(e){var t=[];for(var n in e)x.has(e,n)&&t.push(e[n]);return t},x.pairs=function(e){var t=[];for(var n in e)x.has(e,n)&&t.push([n,e[n]]);return t},x.invert=function(e){var t={};for(var n in e)x.has(e,n)&&(t[e[n]]=n);return t},x.functions=x.methods=function(e){var t=[];for(var n in e)x.isFunction(e[n])&&t.push(n);return t.sort()},x.extend=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]=t[n]}),e},x.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return T(n,function(n){n in e&&(t[n]=e[n])}),t},x.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)x.contains(n,i)||(t[i]=e[i]);return t},x.defaults=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)null==e[n]&&(e[n]=t[n])}),e},x.clone=function(e){return x.isObject(e)?x.isArray(e)?e.slice():x.extend({},e):e},x.tap=function(e,t){return t(e),e};var O=function(e,t,n,r){if(e===t)return 0!==e||1/e==1/t;if(null==e||null==t)return e===t;e instanceof x&&(e=e._wrapped),t instanceof x&&(t=t._wrapped);var i=f.call(e);if(i!=f.call(t))return!1;switch(i){case"[object String]":return e==t+"";case"[object Number]":return e!=+e?t!=+t:0==e?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if("object"!=typeof e||"object"!=typeof t)return!1;for(var s=n.length;s--;)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if("[object Array]"==i){if(o=e.length,u=o==t.length)for(;o--&&(u=O(e[o],t[o],n,r)););}else{var a=e.constructor,l=t.constructor;if(a!==l&&!(x.isFunction(a)&&a instanceof a&&x.isFunction(l)&&l instanceof l))return!1;for(var c in e)if(x.has(e,c)&&(o++,!(u=x.has(t,c)&&O(e[c],t[c],n,r))))break;if(u){for(c in t)if(x.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};x.isEqual=function(e,t){return O(e,t,[],[])},x.isEmpty=function(e){if(null==e)return!0;if(x.isArray(e)||x.isString(e))return 0===e.length;for(var t in e)if(x.has(e,t))return!1;return!0},x.isElement=function(e){return!!e&&1===e.nodeType},x.isArray=w||function(e){return"[object Array]"==f.call(e)},x.isObject=function(e){return e===Object(e)},T(["Arguments","Function","String","Number","Date","RegExp"],function(e){x["is"+e]=function(t){return f.call(t)=="[object "+e+"]"}}),x.isArguments(arguments)||(x.isArguments=function(e){return!!e&&!!x.has(e,"callee")}),"function"!=typeof /./&&(x.isFunction=function(e){return"function"==typeof e}),x.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},x.isNaN=function(e){return x.isNumber(e)&&e!=+e},x.isBoolean=function(e){return e===!0||e===!1||"[object Boolean]"==f.call(e)},x.isNull=function(e){return null===e},x.isUndefined=function(e){return e===void 0},x.has=function(e,t){return l.call(e,t)},x.noConflict=function(){return e._=t,this},x.identity=function(e){return e},x.times=function(e,t,n){for(var r=Array(e),i=0;e>i;i++)r[i]=t.call(n,i);return r},x.random=function(e,t){return null==t&&(t=e,e=0),e+Math.floor(Math.random()*(t-e+1))};var M={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};M.unescape=x.invert(M.escape);var _={escape:RegExp("["+x.keys(M.escape).join("")+"]","g"),unescape:RegExp("("+x.keys(M.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(e){x[e]=function(t){return null==t?"":(""+t).replace(_[e],function(t){return M[e][t]})}}),x.result=function(e,t){if(null==e)return null;var n=e[t];return x.isFunction(n)?n.call(e):n},x.mixin=function(e){T(x.functions(e),function(t){var n=x[t]=e[t];x.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),j.call(this,n.apply(x,e))}})};var D=0;x.uniqueId=function(e){var t=++D+"";return e?e+t:t},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var P=/(.)^/,H={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},B=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(e,t,n){var r;n=x.defaults({},n,x.templateSettings);var i=RegExp([(n.escape||P).source,(n.interpolate||P).source,(n.evaluate||P).source].join("|")+"|$","g"),s=0,o="__p+='";e.replace(i,function(t,n,r,i,u){return o+=e.slice(s,u).replace(B,function(e){return"\\"+H[e]}),n&&(o+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(o+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(o+="';\n"+i+"\n__p+='"),s=u+t.length,t}),o+="';\n",n.variable||(o="with(obj||{}){\n"+o+"}\n"),o="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+o+"return __p;\n";try{r=Function(n.variable||"obj","_",o)}catch(u){throw u.source=o,u}if(t)return r(t,x);var a=function(e){return r.call(this,e,x)};return a.source="function("+(n.variable||"obj")+"){\n"+o+"}",a},x.chain=function(e){return x(e).chain()};var j=function(e){return this._chain?x(e).chain():e};x.mixin(x),T(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];x.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!=e&&"splice"!=e||0!==n.length||delete n[0],j.call(this,n)}}),T(["concat","join","slice"],function(e){var t=r[e];x.prototype[e]=function(){return j.call(this,t.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this),function(e){"use strict";function t(e,t){s.async(function(){e.trigger("promise:resolved",{detail:t}),e.isResolved=!0,e.resolvedValue=t})}function n(e,t){s.async(function(){e.trigger("promise:failed",{detail:t}),e.isRejected=!0,e.rejectedValue=t})}function r(e){var t,n=[],r=new m,i=e.length;i===0&&r.resolve([]);var s=function(e){return function(t){o(e,t)}},o=function(e,t){n[e]=t,--i===0&&r.resolve(n)},u=function(e){r.reject(e)};for(t=0;t<i;t++)e[t].then(s(t),u);return r}function i(e,t){s[e]=t}var s={},o=typeof window!="undefined"?window:{},u=o.MutationObserver||o.WebKitMutationObserver,a;if(typeof process!="undefined"&&{}.toString.call(process)==="[object process]")s.async=function(e,t){process.nextTick(function(){e.call(t)})};else if(u){var f=[],l=new u(function(){var e=f.slice();f=[],e.forEach(function(e){var t=e[0],n=e[1];t.call(n)})}),c=document.createElement("div");l.observe(c,{attributes:!0}),window.addEventListener("unload",function(){l.disconnect(),l=null}),s.async=function(e,t){f.push([e,t]),c.setAttribute("drainQueue","drainQueue")}}else s.async=function(e,t){setTimeout(function(){e.call(t)},1)};var h=function(e,t){this.type=e;for(var n in t){if(!t.hasOwnProperty(n))continue;this[n]=t[n]}},p=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n][0]===t)return n;return-1},d=function(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t},v={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e},on:function(e,t,n){var r=d(this),i,s;e=e.split(/\s+/),n=n||this;while(s=e.shift())i=r[s],i||(i=r[s]=[]),p(i,t)===-1&&i.push([t,n])},off:function(e,t){var n=d(this),r,i,s;e=e.split(/\s+/);while(i=e.shift()){if(!t){n[i]=[];continue}r=n[i],s=p(r,t),s!==-1&&r.splice(s,1)}},trigger:function(e,t){var n=d(this),r,i,s,o,u;if(r=n[e])for(var a=0,f=r.length;a<f;a++)i=r[a],s=i[0],o=i[1],typeof t!="object"&&(t={detail:t}),u=new h(e,t),s.call(o,u)}},m=function(){this.on("promise:resolved",function(e){this.trigger("success",{detail:e.detail})},this),this.on("promise:failed",function(e){this.trigger("error",{detail:e.detail})},this)},g=function(){},y=function(e,t,n,r){var i=typeof n=="function",s,o,u,a;if(i)try{s=n(r.detail),u=!0}catch(f){a=!0,o=f}else s=r.detail,u=!0;s&&typeof s.then=="function"?s.then(function(e){t.resolve(e)},function(e){t.reject(e)}):i&&u?t.resolve(s):a?t.reject(o):t[e](s)};m.prototype={then:function(e,t){var n=new m;return this.isResolved&&s.async(function(){y("resolve",n,e,{detail:this.resolvedValue})},this),this.isRejected&&s.async(function(){y("reject",n,t,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(t){y("resolve",n,e,t)}),this.on("promise:failed",function(e){y("reject",n,t,e)}),n},resolve:function(e){t(this,e),this.resolve=g,this.reject=g},reject:function(e){n(this,e),this.resolve=g,this.reject=g}},v.mixin(m.prototype),e.Promise=m,e.Event=h,e.EventTarget=v,e.all=r,e.configure=i}(window.RSVP={});var EPUBJS=EPUBJS||{};EPUBJS.VERSION="0.1.5",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",EPUBJS.Book=function(e,t){var n=this;this.settings=_.defaults(t||{},{element:!1,storage:!1,saved:!1,online:!0,contained:!1,width:!1,height:!1,spreads:!0,responsive:!0,version:1,restore:!1}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.hooks={beforeChapterDisplay:[]},this.getHooks(),this.online=this.settings.online||navigator.onLine,this.networkListeners(),this.settings.storage!=0&&(this.storage=new fileStorage.storage(this.settings.storage)),this.ready={manifest:new RSVP.Promise,spine:new RSVP.Promise,metadata:new RSVP.Promise,cover:new RSVP.Promise,toc:new RSVP.Promise},this.ready.all=RSVP.all(_.values(this.ready)),e&&(this.opened=this.open(e)),this.settings.element&&this.opened.then(function(){this.rendered=this.renderTo(el)})},EPUBJS.Book.prototype.open=function(e,t){var n=this,r;this.bookUrl=this.urlFrom(e),t&&this.removeSavedSettings();if(this.isSaved())this.applySavedSettings(),this.settings.restore?r=this.restore():r=this.unpack();else{if(this.settings.contained||this.isContained(this.bookUrl)){this.settings.contained=this.contained=!0,this.settings.restore=!0;return}r=n.unpack()}return this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||r.then(n.storeOffline())),r},EPUBJS.Book.prototype.unpack=function(e){var t=this,n=new EPUBJS.Parser,e=e||"META-INF/container.xml";return t.loadXml(t.bookUrl+e).then(function(e){return n.container(e)}).then(function(e){return t.settings.contentsPath=t.bookUrl+e.basePath,t.settings.packageUrl=t.bookUrl+e.packagePath,t.loadXml(t.settings.packageUrl)}).then(function(e){return n.package(e,t.settings.contentsPath)}).then(function(e){return t.contents=e,t.manifest=t.contents.manifest,t.spine=t.contents.spine,t.spineIndexByURL=t.contents.spineIndexByURL,t.metadata=t.contents.metadata,t.cover=t.contents.cover=t.settings.contentsPath+e.coverPath,t.spineNodeIndex=t.contents.spineNodeIndex=e.spineNodeIndex,t.ready.manifest.resolve(t.contents.manifest),t.ready.spine.resolve(t.contents.spine),t.ready.metadata.resolve(t.contents.metadata),t.ready.cover.resolve(t.contents.cover),t.settings.tocUrl=t.settings.contentsPath+e.tocPath,t.loadXml(t.settings.tocUrl)}).then(function(e){return n.toc(e)}).then(function(e){t.toc=t.contents.toc=e,t.ready.toc.resolve(t.contents.toc)}).then(null,function(e){console.log("Error:",e)})},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc},EPUBJS.Book.prototype.networkListeners=function(){var e=this;window.addEventListener("offline",function(t){e.online=!1,e.trigger("book:offline")},!1),window.addEventListener("online",function(t){e.online=!0,e.trigger("book:online")},!1),window.addEventListener("beforeunload",function(t){e.saveSettings(),e.settings.restore&&e.saveContents(),e.trigger("book:unload")},!1)},EPUBJS.Book.prototype.loadXml=function(e){return this.settings.storage?this.storage.getXml(e):EPUBJS.core.request(e,"xml")},EPUBJS.Book.prototype.urlFrom=function(e){var t=e.search("://")!=-1,n=e[0]=="/",r=window.location,i=r.origin||r.protocol+"//"+r.host;e[e.length-1]!="/"&&(e+="/");if(t)return e;if(!t&&n)return i+e;if(!t&&!n)return i+EPUBJS.core.folder(r.pathname)+e},EPUBJS.Book.prototype.unarchive=function(e){var t;return this.settings.storage==0&&(this.settings.storage=!0,this.storage=new fileStorage.storage),t=new EPUBJS.Unarchiver(e),t},EPUBJS.Book.prototype.isContained=function(e){var t=e.lastIndexOf("."),n=e.slice(t+1);return!n||n!="epub"&&n!="zip"?!1:!0},EPUBJS.Book.prototype.isSaved=function(){var e=this.bookUrl+":"+this.settings.version,t=localStorage.getItem(e);return!localStorage||t===null?!1:!0},EPUBJS.Book.prototype.removeSavedSettings=function(){var e=this.bookUrl+":"+this.settings.version;localStorage.removeItem(e),this.settings.stored=!1},EPUBJS.Book.prototype.applySavedSettings=function(){var e=this.bookUrl+":"+this.settings.version;stored=JSON.parse(localStorage.getItem(e));if(EPUBJS.VERSION!=stored.EPUBJSVERSION)return!1;this.settings=_.defaults(this.settings,stored)},EPUBJS.Book.prototype.saveSettings=function(){var e=this.bookUrl+":"+this.settings.version;this.render&&(this.settings.previousLocationCfi=this.render.currentLocationCfi),localStorage.setItem(e,JSON.stringify(this.settings))},EPUBJS.Book.prototype.saveContents=function(){var e=this.settings.contentsPath+":"+this.settings.version;localStorage.setItem(e,JSON.stringify(this.contents))},EPUBJS.Book.prototype.renderTo=function(e){var t=this;return this.settings.element=e,this.opened.then(function(){return t.render=new EPUBJS.Renderer(t),t.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var e;return this.settings.previousLocationCfi?e=this.displayChapter(this.settings.previousLocationCfi):e=this.displayChapter(this.spinePos),e},EPUBJS.Book.prototype.restore=function(){var e=this,t=this.settings.contentsPath+":"+this.settings.version,n=new RSVP.Promise,r=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL"],i=!1,s=localStorage.getItem(t);return this.settings.contentsPath&&s&&(this.contents=JSON.parse(s),r.forEach(function(t){e[t]=e.contents[t],e[t]||(i=!0)})),i||!s||!this.contents?(this.removeSavedSettings(),this.unpack()):(this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),n.resolve(),n)},EPUBJS.Book.prototype.displayChapter=function(e,t){var n=this,r,i,s;return _.isNumber(e)?s=e:(i=new EPUBJS.EpubCFI(e),s=i.spinePos),s>=this.spine.length?!1:s<0?!1:(this.spinePos=s,this.chapter=new EPUBJS.Chapter(this.spine[s]),r=n.render.chapter(this.chapter),i?r.then(function(t){t.currentLocationCfi=e,t.gotoCfiFragment(i)}):t&&r.then(function(e){e.gotoChapterEnd()}),this.settings.storage||r.then(function(){n.preloadNextChapter()}),r)},EPUBJS.Book.prototype.nextPage=function(){var e=this.render.nextPage();if(!e)return this.nextChapter()},EPUBJS.Book.prototype.prevPage=function(){var e=this.render.prevPage();if(!e)return this.prevChapter()},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos++,this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.prevChapter=function(){return this.spinePos--,this.displayChapter(this.spinePos,!0)},EPUBJS.Book.prototype.goto=function(e){var t=e.split("#"),n=t[0],r=t[1]||!1,i=n.search("://")==-1?this.settings.contentsPath+n:n,s=this.spineIndexByURL[i],o;return n||(s=this.chapter.spinePos),typeof s!="number"?!1:s!=this.chapter.spinePos||!this.chapter?this.displayChapter(s).then(function(){r&&o.render.section(r)}):(r&&this.render.section(r),(new RSVP.Promise).resolve(this.currentChapter))},EPUBJS.Book.prototype.preloadNextChapter=function(){var e=document.createElement("iframe");next;if(this.spinePos>=this.spine.length)return!1;next=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(next.href)},EPUBJS.Book.prototype.storeOffline=function(){var e=this,t=_.values(this.manifest);return EPUBJS.storage.batch(t).then(function(){e.settings.stored=!0,e.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){return this.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(e,t,n){this.renderer.setStyle(e,t,n),this.settings.styles[e]=t},EPUBJS.Book.prototype.removeStyle=function(e,t,n){this.renderer.removeStyle(e),delete this.settings.styles[e]=""},EPUBJS.Book.prototype.getHooks=function(){var e=this,t;plugTypes=_.values(this.hooks);for(plugType in this.hooks)t=_.values(EPUBJS.Hooks[plugType]),t.forEach(function(t){e.registerHook(plugType,t)})},EPUBJS.Book.prototype.registerHook=function(e,t){var n=this;typeof this.hooks[e]!="undefined"?typeof t=="function"?this.hooks[e].push(t):Array.isArray(t)&&t.forEach(function(t){n.hooks[e].push(t)}):this.hooks[e]=[func]},EPUBJS.Book.prototype.triggerHooks=function(e,t,n){function s(){i--,i<=0&&t&&t()}var r,i;if(typeof this.hooks[e]=="undefined")return!1;r=this.hooks[e],i=r.length,r.forEach(function(e){e(s,n)})},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),EPUBJS.Chapter=function(e){this.href=e.href,this.id=e.id,this.spinePos=e.index,this.properties=e.properties,this.linear=e.linear,this.pages=1},EPUBJS.Chapter.prototype.contents=function(e){return e?e.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(e){var t=new RSVP.Promise;return e?e.getUrl(href):(t.resolve(this.href),t)},EPUBJS.Chapter.prototype.setPages=function(e){this.pages=e},EPUBJS.Chapter.prototype.getPages=function(e){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID};var EPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(e){return document.getElementById(e)},EPUBJS.core.getEls=function(e){return document.getElementsByClassName(e)},EPUBJS.core.request=function(e,t){function i(){if(this.readyState===this.DONE)if(this.status===200){var e;t=="xml"?e=this.responseXML:t=="json"?e=JSON.parse(this.response):e=this.response,n.resolve(e)}else n.reject(this)}var n=new RSVP.Promise,r=new XMLHttpRequest;return r.open("GET",e),r.onreadystatechange=i,t=="blob"&&(r.responseType=t),t=="json"&&r.setRequestHeader("Accept","application/json"),t=="xml"&&r.overrideMimeType("text/xml"),r.send(),n},EPUBJS.core.toArray=function(e){var t=[];for(member in e){var n;e.hasOwnProperty(member)&&(n=e[member],n.ident=member,t.push(n))}return t},EPUBJS.core.folder=function(e){var t=e.lastIndexOf("/"),n=e.slice(0,t+1);return n},EPUBJS.core.dataURLToBlob=function(e){var t=";base64,";if(e.indexOf(t)==-1){var n=e.split(","),r=n[0].split(":")[1],i=n[1];return new Blob([i],{type:r})}var n=e.split(t),r=n[0].split(":")[1],i=window.atob(n[1]),s=i.length,o=new Uint8Array(s);for(var u=0;u<s;++u)o[u]=i.charCodeAt(u);return new Blob([o],{type:r})},EPUBJS.core.addScript=function(e,t,n){var r,i;i=!1,r=document.createElement("script"),r.type="text/javascript",r.async=!1,r.src=e,r.onload=r.onreadystatechange=function(){!i&&(!this.readyState||this.readyState=="complete")&&(i=!0,t&&t())},n=n||document.body,n.appendChild(r)},EPUBJS.core.addScripts=function(e,t,n){var r=e.length,i=0,s=function(){i++,r==i?t&&t():EPUBJS.core.loadScript(e[i],s,n)};EPUBJS.core.addScript(e[i],s,n)},EPUBJS.core.addCss=function(e,t,n){var r,i;i=!1,r=document.createElement("link"),r.type="text/css",r.rel="stylesheet",r.href=e,r.onload=r.onreadystatechange=function(){!i&&(!this.readyState||this.readyState=="complete")&&(i=!0,t&&t())},n=n||document.body,n.appendChild(r)},EPUBJS.core.prefixed=function(e){var t=["Webkit","Moz","O","ms"],n=["-Webkit-","-moz-","-o-","-ms-"],r=e[0].toUpperCase()+e.slice(1),i=t.length,s=0;if(typeof document.body.style[e]!="undefined")return e;for(;s<i;s++)if(typeof document.body.style[t[s]+r]!="undefined")return t[s]+r;return e},EPUBJS.EpubCFI=function(e){if(e)return this.parse(e)},EPUBJS.EpubCFI.prototype.generateChapter=function(e,t,n){var e=e+1,r="/"+e+"/";return r+=(t+1)*2,n&&(r+="["+n+"]"),r+="!",r},EPUBJS.EpubCFI.prototype.generateFragment=function(e,t){var n=this.pathTo(e),r=[];return t&&r.push(t),n.forEach(function(e){r.push((e.index+1)*2),e.id&&e.id.slice(0,7)!="@EPUBJS"&&r.push("["+e.id+"]")}),r.join("/")},EPUBJS.EpubCFI.prototype.pathTo=function(e){var t=[],n;while(e&&e.parentNode!==null)n=e.parentNode.children,t.unshift({id:e.id,tagName:e.tagName,index:n?Array.prototype.indexOf.call(n,e):0}),e=e.parentNode;return t},EPUBJS.EpubCFI.prototype.getChapter=function(e){var t=e.split("!");return t[0]},EPUBJS.EpubCFI.prototype.getFragment=function(e){var t=e.split("!");return t[1]},EPUBJS.EpubCFI.prototype.getOffset=function(e){var t=e.split(":");return[t[0],t[1]]},EPUBJS.EpubCFI.prototype.parse=function(e){var t={},n,r,i,s;return t.chapter=this.getChapter(e),t.fragment=this.getFragment(e),t.spinePos=parseInt(t.chapter.split("/")[2])/2-1||0,n=t.chapter.match(/\[(.*)\]/),t.spineId=n[1]||!1,r=t.fragment.split("/"),i=r[r.length-1],t.sections=[],parseInt(i)%2&&(s=this.getOffset(),t.text=parseInt(s[0]),t.character=parseInt(s[1]),r.pop()),r.forEach(function(e){var n,r,i;if(!e)return;n=parseInt(e)/2-1,r=e.match(/\[(.*)\]/),r&&r[1]&&(i=r[1]),t.sections.push({index:n,id:i||!1})}),t},EPUBJS.EpubCFI.prototype.getElement=function(e,t){var t=t||document,n=e.sections,r=t.getElementsByTagName("html")[0],i=Array.prototype.slice.call(r.children),s,o,u,a,f;n.shift();while(n.length>0)u=n.shift(),u.id?r=e.doc.querySelector("#"+u.id):(r=i[u.index],i||console.error("No Kids",r)),r||console.error("No Element For",u),i=Array.prototype.slice.call(r.children);return r},EPUBJS.Events=function(e,t){return this.events={},t?this.el=t:this.el=document.createElement("div"),e.createEvent=this.createEvent,e.tell=this.tell,e.listen=this.listen,e.deafen=this.deafen,e.listenUntil=this.listenUntil,this},EPUBJS.Events.prototype.createEvent=function(e){var t=new CustomEvent(e);return this.events[e]=t,t},EPUBJS.Events.prototype.tell=function(e,t){var n;this.events[e]?n=this.events[e]:(console.warn("No event:",e,"defined yet, creating."),n=this.createEvent(e)),t&&(n.msg=t),this.el.dispatchEvent(n)},EPUBJS.Events.prototype.listen=function(e,t,n){if(!this.events[e]){console.warn("No event:",e,"defined yet, creating."),this.createEvent(e);return}n?this.el.addEventListener(e,t.bind(n),!1):this.el.addEventListener(e,t,!1)},EPUBJS.Events.prototype.deafen=function(e,t){this.el.removeEventListener(e,t,!1)},EPUBJS.Events.prototype.listenUntil=function(e,t,n,r){function i(){this.deafen(e,n),this.deafen(t,i)}this.listen(e,n,r),this.listen(t,i,this)},EPUBJS.Hooks=function(){"use strict";return{register:function(e){this[e]===undefined&&(this[e]={});if(typeof this[e]!="object")throw"Already registered: "+e;return this[e]}}}(),EPUBJS.Parser=function(e){this.baseUrl=e||""},EPUBJS.Parser.prototype.container=function(e){var t=e.querySelector("rootfile"),n=t.getAttribute("full-path"),r=EPUBJS.core.folder(n);return{packagePath:n,basePath:r}},EPUBJS.Parser.prototype.package=function(e,t){var n=this;t&&(this.baseUrl=t);var r=e.querySelector("metadata"),i=e.querySelector("manifest"),s=e.querySelector("spine"),o=n.manifest(i),u=n.findTocPath(i),a=n.findCoverPath(i),f=Array.prototype.indexOf.call(s.parentNode.childNodes,s),l=n.spine(s,o),c={};return l.forEach(function(e){c[e.href]=e.index}),{metadata:n.metadata(r),spine:l,manifest:o,tocPath:u,coverPath:a,spineNodeIndex:f,spineIndexByURL:c}},EPUBJS.Parser.prototype.findTocPath=function(e){var t=e.querySelector("item[media-type='application/x-dtbncx+xml']");return t.getAttribute("href")},EPUBJS.Parser.prototype.findCoverPath=function(e){var t=e.querySelector("item[properties='cover-image']");return t.getAttribute("href")},EPUBJS.Parser.prototype.metadata=function(e){var t={},n=this;return t.bookTitle=n.getElement(e,"title"),t.creator=n.getElement(e,"creator"),t.description=n.getElement(e,"description"),t.pubdate=n.getElement(e,"date"),t.publisher=n.getElement(e,"publisher"),t.identifier=n.getElement(e,"identifier"),t.language=n.getElement(e,"language"),t.rights=n.getElement(e,"rights"),t.modified_date=n.querySelector(e,"meta[property='dcterms:modified']"),t.layout=n.querySelector(e,"meta[property='rendition:orientation']"),t.orientation=n.querySelector(e,"meta[property='rendition:orientation']"),t.spread=n.querySelector(e,"meta[property='rendition:spread']"),t},EPUBJS.Parser.prototype.getElement=function(e,t){var n=e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",t),r;return n?(r=n[0],r?r.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelector=function(e,t){var n=e.querySelector(t);return n?n.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(e){var t=this.baseUrl,n={},r=e.querySelectorAll("item"),i=Array.prototype.slice.call(r);return i.forEach(function(e){var r=e.getAttribute("id"),i=e.getAttribute("href")||"",s=e.getAttribute("media-type")||"";n[r]={href:t+i,type:s}}),n},EPUBJS.Parser.prototype.spine=function(e,t){var n=[],r=e.getElementsByTagName("itemref"),i=Array.prototype.slice.call(r);return i.forEach(function(e,r){var i=e.getAttribute("idref"),s={id:i,linear:e.getAttribute("linear")||"",properties:e.getAttribute("properties")||"",href:t[i].href,index:r};n.push(s)}),n},EPUBJS.Parser.prototype.toc=function(e){function r(e,t,n){var n=n||[];return items=Array.prototype.slice.call(e),items.forEach(function(e){var t=e.getAttribute("id"),i=e.querySelector("content"),s=i.getAttribute("src"),o=s.split("#"),u=e.querySelector("navLabel"),a=u.textContent?u.textContent:"",f=e.querySelectorAll("navPoint");n.push({id:t,href:s,label:a,subitems:f.length?r(e.querySelectorAll("navPoint"),e,n):!1})}),n}var t=[],n=e.querySelector("navMap");return r(n.querySelectorAll("navPoint"),n)},EPUBJS.Renderer=function(e){var t=e.settings.element;this.book=e,this.settings=e.settings;if(_.isElement(t))this.el=t;else{if(typeof t!="string"){console.error("Not an Element");return}this.el=EPUBJS.core.getEl(t)}e.registerHook("beforeChapterDisplay",[this.replaceLinks.bind(this),this.replaceResources.bind(this)]),this.crossBrowserColumnCss(),this.epubcfi=new EPUBJS.EpubCFI,this.initialize(),this.listeners()},EPUBJS.Renderer.prototype.initialize=function(){this.iframe=document.createElement("iframe"),this.resizeIframe(!1,this.el.clientWidth,this.el.clientHeight),this.on("book:resized",this.resizeIframe,this),this.el.appendChild(this.iframe)},EPUBJS.Renderer.prototype.listeners=function(){this.resized=_.debounce(this.onResized.bind(this),10),window.addEventListener("resize",this.resized,!1)},EPUBJS.Renderer.prototype.chapter=function(e){var t=this,n=this.settings.stored?this.store:!1;return this.currentChapter&&this.trigger("book:chapterDestroyed"),this.currentChapter=e,this.chapterPos=1,this.pageIds={},this.leftPos=0,this.currentChapterCfi=this.epubcfi.generateChapter(this.book.spineNodeIndex,e.spinePos,e.id),this.visibileEl=!1,e.url(n).then(function(e){return t.setIframeSrc(e)})},EPUBJS.Renderer.prototype.onResized=function(){this.trigger("book:resized",{width:this.el.clientWidth,height:this.el.clientHeight}),this.reformat()},EPUBJS.Renderer.prototype.reformat=function(){var e=this;this.formatSpread(),setTimeout(function(){e.calcPages(),e.currentLocationCfi&&e.gotoCfiFragment(e.currentLocationCfi)},10)},EPUBJS.Renderer.prototype.destroy=function(){window.removeEventListener("resize",this.resized,!1)},EPUBJS.Renderer.prototype.resizeIframe=function(e,t,n){var r,i;e?(r=e.width,i=e.height):(r=t,i=n),this.iframe.height=i,r%2!=0&&(r+=1),this.iframe.width=r},EPUBJS.Renderer.prototype.crossBrowserColumnCss=function(){EPUBJS.Renderer.columnAxis=EPUBJS.core.prefixed("columnAxis"),EPUBJS.Renderer.columnGap=EPUBJS.core.prefixed("columnGap"),EPUBJS.Renderer.columnWidth=EPUBJS.core.prefixed("columnWidth")},EPUBJS.Renderer.prototype.setIframeSrc=function(e){var t=this,n=new RSVP.Promise;return this.visible(!1),this.iframe.src=e,this.iframe.onload=function(){t.doc=t.iframe.contentDocument,t.docEl=t.doc.documentElement,t.bodyEl=t.doc.body,t.applyStyles(),t.formatSpread(),t.beforeDisplay(function(){t.calcPages(),t.currentLocationCfi=t.getPageCfi(),t.trigger("book:chapterDisplayed"),t.visible(!0)}),n.resolve(t)},n},EPUBJS.Renderer.prototype.formatSpread=function(){var e=2,t=800;this.colWidth&&(this.OldcolWidth=this.colWidth,this.OldspreadWidth=this.spreadWidth),this.elWidth=this.iframe.width,this.gap=this.gap||Math.ceil(this.elWidth/8),this.elWidth<t||this.settings.single?(this.spread=!1,e=1,this.colWidth=Math.floor(this.elWidth/e)):(this.spread=!0,this.colWidth=Math.floor((this.elWidth-this.gap)/e)),this.spreadWidth=(this.colWidth+this.gap)*e,this.docEl.style.overflow="hidden",this.docEl.style.width=this.elWidth,this.docEl.style.height=this.el.clientHeight+"px",this.docEl.style[EPUBJS.Renderer.columnAxis]="horizontal",this.docEl.style[EPUBJS.Renderer.columnGap]=this.gap+"px",this.docEl.style[EPUBJS.Renderer.columnWidth]=this.colWidth+"px"},EPUBJS.Renderer.prototype.fixedLayout=function(){this.paginated=!1,this.setLeft(0),this.docEl.style.width=this.elWidth,this.docEl.style.height="auto",this.docEl.style[EPUBJS.core.columnWidth]="auto",this.docEl.style.overflow="auto",this.displayedPages=1},EPUBJS.Renderer.prototype.setStyle=function(e,t,n){n&&(e=EPUBJS.core.prefixed(e)),this.bodyEl&&(this.bodyEl.style[e]=t)},EPUBJS.Renderer.prototype.removeStyle=function(e){this.bodyEl&&(this.bodyEl.style[e]="")},EPUBJS.Renderer.prototype.applyStyles=function(){var e=this.book.settings.styles;for(style in e)this.setStyle(style,e[style])},EPUBJS.Renderer.prototype.gotoChapterEnd=function(){this.chapterEnd()},EPUBJS.Renderer.prototype.visible=function(e){if(typeof e=="undefined")return this.iframe.style.visibility;e==1?this.iframe.style.visibility="visible":e==0&&(this.iframe.style.visibility="hidden")},EPUBJS.Renderer.prototype.calcPages=function(){this.totalWidth=this.docEl.scrollWidth,this.displayedPages=Math.ceil(this.totalWidth/this.spreadWidth),this.currentChapter.pages=this.displayedPages},EPUBJS.Renderer.prototype.nextPage=function(){return this.chapterPos<this.displayedPages?(this.chapterPos++,this.leftPos+=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.trigger("book:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.prevPage=function(){return this.chapterPos>1?(this.chapterPos--,this.leftPos-=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.trigger("book:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.chapterEnd=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.setLeft=function(e){this.doc.defaultView.scrollTo(e,0)},EPUBJS.Renderer.prototype.replaceLinks=function(e){var t=this.doc.querySelectorAll("[href]"),n=Array.prototype.slice.call(t),r=this;n.forEach(function(e){var t,n=e.getAttribute("href"),i=n.search("://"),s=n[0]=="#";i!=-1?e.setAttribute("target","_blank"):e.onclick=function(){r.book.goto(n)}}),e&&e()},EPUBJS.Renderer.prototype.replaceResources=function(e){var t,n,r;if(this.book.online&&!this.book.contained||EPUBJS.storage.getStorageType()=="filesystem")return e&&e(),!1;t=this.doc.querySelectorAll("[src]"),n=Array.prototype.slice.call(t),r=n.length,n.forEach(function(t){var n=t.getAttribute("src"),i=this.book.basePath+n;EPUBJS.storage.get(i,function(n){t.setAttribute("src",n),r--,r<=0&&e&&e()})}.bind(this))},EPUBJS.Renderer.prototype.page=function(e){return e>=1&&e<=this.displayedPages?(this.chapterPos=e,this.leftPos=this.spreadWidth*(e-1),this.setLeft(this.leftPos),!0):(console.log("false",e,this.displayedPages),!1)},EPUBJS.Renderer.prototype.section=function(e){var t=this.doc.getElementById(e),n,r;t&&this.pageByElement(t)},EPUBJS.Renderer.prototype.pageByElement=function(e){var t,n;if(!e)return;t=this.leftPos+e.getBoundingClientRect().left,n=Math.floor(t/this.spreadWidth)+1,this.page(n)},EPUBJS.Renderer.prototype.beforeDisplay=function(e){this.book.triggerHooks("beforeChapterDisplay",e.bind(this),this)},EPUBJS.Renderer.prototype.walk=function(e){var t,e,n,r,i=e,s,o=[i],u=1e4,a=0;while(!t&&o.length){e=o.shift(),this.isElementVisible(e)&&(t=e);if(!t&&e&&e.childElementCount>0){n=e.children,r=n.length;for(var f=0;f<r;f++)n[f]!=s&&o.push(n[f])}!t&&o.length==0&&i&&i.parentNode!==null&&(o.push(i.parentNode),s=i,i=i.parentNode),a++;if(a>u){console.error("ENDLESS LOOP");break}}return t},EPUBJS.Renderer.prototype.getPageCfi=function(){var e=this.visibileEl;return this.visibileEl=this.findFirstVisible(e),this.visibileEl.id||(this.visibileEl.id="@EPUBJS-PAGE-"+this.chapterPos),this.pageIds[this.chapterPos]=this.visibileEl.id,this.epubcfi.generateFragment(this.visibileEl,this.currentChapterCfi)},EPUBJS.Renderer.prototype.gotoCfiFragment=function(e){var t;_.isString(e)&&(e=this.epubcfi.parse(e)),t=this.epubcfi.getElement(e,this.doc),this.pageByElement(t)},EPUBJS.Renderer.prototype.findFirstVisible=function(e){var t=e||this.bodyEl,n;return n=this.walk(t),n?n:e},EPUBJS.Renderer.prototype.isElementVisible=function(e){var t;if(e){t=e.getBoundingClientRect().left;if(t>=0&&t<this.spreadWidth)return!0}return!1},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype),EPUBJS.Unarchiver=function(e,t){this.libPath=EPUBJS.filePath+"libs/",this.zipUrl=e,this.callback=t,this.loadLib(function(){this.getZip(this.zipUrl)}.bind(this))},EPUBJS.Unarchiver.prototype.loadLib=function(e){typeof zip!="undefined"&&e(),EPUBJS.core.loadScript(this.libPath+"zip.js",function(){zip.workerScriptsPath=this.libPath,e()}.bind(this))},EPUBJS.Unarchiver.prototype.getZip=function(e){var t=new EPUBJS.core.loadFile(e);t.succeeded=function(e){this.getEntries(e,this.toStorage.bind(this))}.bind(this),t.failed=this.failed,t.start()},EPUBJS.Unarchiver.prototype.getEntries=function(e,t){zip.createReader(new zip.BlobReader(e),function(e){e.getEntries(t)},this.failed)},EPUBJS.Unarchiver.prototype.failed=function(e){console.log("Error:",e)},EPUBJS.Unarchiver.prototype.afterSaved=function(e){this.callback()},EPUBJS.Unarchiver.prototype.toStorage=function(e){function s(){i--,i==0&&r.afterSaved()}var t=0,n=20,r=this,i=e.length;e.forEach(function(e){setTimeout(function(e){r.saveEntryFileToStorage(e,s)},t,e),t+=n}),console.log("time",t)},EPUBJS.Unarchiver.prototype.saveEntryFileToStorage=function(e,t){var n=this;e.getData(new zip.BlobWriter,function(n){EPUBJS.storage.save(e.filename,n,t)})}; |