filesbox/web/dist/reader/js/reader.min.js
2024-07-26 14:10:54 +08:00

8 lines
36 KiB
JavaScript

/*!
* @overview RSVP - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2016 Yehuda Katz, Tom Dale, Stefan Penner and contributors
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE
* @version 3.6.2
*/(function(n,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):r(n.RSVP=n.RSVP||{})})(this,function(n){"use strict";function r(e,t){for(var o=0,s=e.length;o<s;o++)if(e[o]===t)return o;return-1}function i(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}function c(e,t){if(arguments.length!==2)return E[e];E[e]=t}function a(e){var t=typeof e;return e!==null&&(t==="object"||t==="function")}function l(e){return typeof e=="function"}function h(e){return e!==null&&typeof e=="object"}function d(e){return e!==null&&typeof e=="object"}function m(){setTimeout(function(){for(var e=0;e<ee.length;e++){var t=ee[e],o=t.payload;o.guid=o.key+o.id,o.childGuid=o.key+o.childId,o.error&&(o.stack=o.error.stack),E.trigger(t.name,t.payload)}ee.length=0},50)}function p(e,t,o){ee.push({name:e,payload:{key:t._guidKey,id:t._id,eventName:e,detail:t._result,childId:o&&o._id,label:t._label,timeStamp:je(),error:E["instrument-with-stack"]?new Error(t._label):null}})===1&&m()}function v(e,t){var o=this;if(e&&typeof e=="object"&&e.constructor===o)return e;var s=new o(C,t);return b(s,e),s}function k(){return new TypeError("A promises callback cannot return that same promise.")}function C(){}function R(e){try{return e.then}catch(t){return Q.error=t,Q}}function j(e,t,o,s){try{e.call(t,o,s)}catch(u){return u}}function N(e,t,o){E.async(function(s){var u=!1,f=j(o,t,function(y){u||(u=!0,t!==y?b(s,y,void 0):_(s,y))},function(y){u||(u=!0,O(s,y))},"Settle: "+(s._label||" unknown promise"));!u&&f&&(u=!0,O(s,f))},e)}function S(e,t){t._state===B?_(e,t._result):t._state===V?(t._onError=null,O(e,t._result)):L(t,void 0,function(o){t!==o?b(e,o,void 0):_(e,o)},function(o){return O(e,o)})}function x(e,t,o){t.constructor===e.constructor&&o===I&&e.constructor.resolve===v?S(e,t):o===Q?(O(e,Q.error),Q.error=null):l(o)?N(e,t,o):_(e,t)}function b(e,t){e===t?_(e,t):a(t)?x(e,t,R(t)):_(e,t)}function g(e){e._onError&&e._onError(e._result),D(e)}function _(e,t){e._state===K&&(e._result=t,e._state=B,e._subscribers.length===0?E.instrument&&p("fulfilled",e):E.async(D,e))}function O(e,t){e._state===K&&(e._state=V,e._result=t,E.async(g,e))}function L(e,t,o,s){var u=e._subscribers,f=u.length;e._onError=null,u[f]=t,u[f+B]=o,u[f+V]=s,f===0&&e._state&&E.async(D,e)}function D(e){var t=e._subscribers,o=e._state;if(E.instrument&&p(o===B?"fulfilled":"rejected",e),t.length!==0){for(var s=void 0,u=void 0,f=e._result,y=0;y<t.length;y+=3)s=t[y],u=t[y+o],s?H(o,s,u,f):u(f);e._subscribers.length=0}}function F(){this.error=null}function T(e,t){try{return e(t)}catch(o){return le.error=o,le}}function H(e,t,o,s){var u=l(o),f=void 0,y=void 0;if(u){if((f=T(o,s))===le)y=f.error,f.error=null;else if(f===t)return void O(t,k())}else f=s;t._state!==K||(u&&y===void 0?b(t,f):y!==void 0?O(t,y):e===B?_(t,f):e===V&&O(t,f))}function z(e,t){var o=!1;try{t(function(s){o||(o=!0,b(e,s))},function(s){o||(o=!0,O(e,s))})}catch(s){O(e,s)}}function I(e,t,o){var s=this,u=s._state;if(u===B&&!e||u===V&&!t)return E.instrument&&p("chained",s,s),s;s._onError=null;var f=new s.constructor(C,o),y=s._result;if(E.instrument&&p("chained",s,f),u===K)L(s,f,e,t);else{var P=u===B?e:t;E.async(function(){return H(u,f,P,y)})}return f}function X(e,t,o){return e===B?{state:"fulfilled",value:o}:{state:"rejected",reason:o}}function ne(e,t){return U(e)?new ue(this,e,!0,t).promise:this.reject(new TypeError("Promise.all must be called with an array"),t)}function G(e,t){var o=this,s=new o(C,t);if(!U(e))return O(s,new TypeError("Promise.race must be called with an array")),s;for(var u=0;s._state===K&&u<e.length;u++)L(o.resolve(e[u]),void 0,function(f){return b(s,f)},function(f){return O(s,f)});return s}function Xe(e,t){var o=this,s=new o(C,t);return O(s,e),s}function Ue(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function Ve(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function pe(){this.value=void 0}function He(e){try{return e.then}catch(t){return q.value=t,q}}function me(e,t,o){try{e.apply(t,o)}catch(s){return q.value=s,q}}function qe(e,t){for(var o={},s=e.length,u=new Array(s),f=0;f<s;f++)u[f]=e[f];for(var y=0;y<t.length;y++)o[t[y]]=u[y+1];return o}function Je(e){for(var t=e.length,o=new Array(t-1),s=1;s<t;s++)o[s-1]=e[s];return o}function Ye(e,t){return{then:function(o,s){return e.call(t,o,s)}}}function ve(e,t){var o=function(){for(var s=this,u=arguments.length,f=new Array(u+1),y=!1,P=0;P<u;++P){var A=arguments[P];if(!y){if((y=Qe(A))===Ne){var Y=new w(C);return O(Y,Ne.value),Y}y&&y!==!0&&(A=Ye(y,A))}f[P]=A}var M=new w(C);return f[u]=function(ze,Ke){ze?O(M,ze):t===void 0?b(M,Ke):t===!0?b(M,Je(arguments)):U(t)?b(M,qe(arguments,t)):b(M,Ke)},y?We(M,f,e,s):Ge(M,f,e,s)};return o.__proto__=e,o}function Ge(e,t,o,s){var u=me(o,s,t);return u===q&&O(e,u.value),e}function We(e,t,o,s){return w.all(t).then(function(u){var f=me(o,s,u);return f===q&&O(e,f.value),e})}function Qe(e){return!(!e||typeof e!="object")&&(e.constructor===w||He(e))}function ye(e,t){return w.all(e,t)}function Ze(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||typeof t!="object"&&typeof t!="function"?e:t}function et(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function ge(e,t){return U(e)?new Pe(w,e,t).promise:w.reject(new TypeError("Promise.allSettled must be called with an array"),t)}function we(e,t){return w.race(e,t)}function tt(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||typeof t!="object"&&typeof t!="function"?e:t}function nt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function ke(e,t){return h(e)?new Le(w,e,t).promise:w.reject(new TypeError("Promise.hash must be called with an object"),t)}function rt(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||typeof t!="object"&&typeof t!="function"?e:t}function ot(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function Ce(e,t){return h(e)?new Ae(w,e,!1,t).promise:w.reject(new TypeError("RSVP.hashSettled must be called with an object"),t)}function _e(e){throw setTimeout(function(){throw e}),e}function be(e){var t={resolve:void 0,reject:void 0};return t.promise=new w(function(o,s){t.resolve=o,t.reject=s},e),t}function xe(e,t,o){return U(e)?l(t)?w.all(e,o).then(function(s){for(var u=s.length,f=new Array(u),y=0;y<u;y++)f[y]=t(s[y]);return w.all(f,o)}):w.reject(new TypeError("RSVP.map expects a function as a second argument"),o):w.reject(new TypeError("RSVP.map must be called with an array"),o)}function re(e,t){return w.resolve(e,t)}function Ee(e,t){return w.reject(e,t)}function oe(e,t){return w.all(e,t)}function it(e,t){return w.resolve(e,t).then(function(o){return oe(o,t)})}function Se(e,t,o){return U(e)||h(e)&&e.then!==void 0?l(t)?(U(e)?oe(e,o):it(e,o)).then(function(s){for(var u=s.length,f=new Array(u),y=0;y<u;y++)f[y]=t(s[y]);return oe(f,o).then(function(P){for(var A=new Array(u),Y=0,M=0;M<u;M++)P[M]&&(A[Y]=s[M],Y++);return A.length=Y,A})}):w.reject(new TypeError("RSVP.filter expects function as a second argument"),o):w.reject(new TypeError("RSVP.filter must be called with an array or promise"),o)}function ie(e,t){J[Z]=e,J[Z+1]=t,(Z+=2)===2&&Be()}function st(){var e=process.nextTick,t=process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);return Array.isArray(t)&&t[1]==="0"&&t[2]==="10"&&(e=setImmediate),function(){return e(W)}}function at(){return de!==void 0?function(){de(W)}:se()}function ct(){var e=0,t=new $e(W),o=document.createTextNode("");return t.observe(o,{characterData:!0}),function(){return o.data=e=++e%2}}function lt(){var e=new MessageChannel;return e.port1.onmessage=W,function(){return e.port2.postMessage(0)}}function se(){return function(){return setTimeout(W,1)}}function W(){for(var e=0;e<Z;e+=2)(0,J[e])(J[e+1]),J[e]=void 0,J[e+1]=void 0;Z=0}function ut(){try{var e=require,t=e("vertx");return de=t.runOnLoop||t.runOnContext,at()}catch(o){return se()}}function Oe(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function ae(){E.on.apply(E,arguments)}function Re(){E.off.apply(E,arguments)}var ce={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(e,t){if(typeof t!="function")throw new TypeError("Callback must be a function");var o=i(this),s=void 0;s=o[e],s||(s=o[e]=[]),r(s,t)===-1&&s.push(t)},off:function(e,t){var o=i(this),s=void 0,u=void 0;if(!t)return void(o[e]=[]);s=o[e],(u=r(s,t))!==-1&&s.splice(u,1)},trigger:function(e,t,o){var s=i(this),u=void 0;if(u=s[e])for(var f=0;f<u.length;f++)(0,u[f])(t,o)}},E={instrument:!1};ce.mixin(E);var Te=void 0;Te=Array.isArray?Array.isArray:function(e){return Object.prototype.toString.call(e)==="[object Array]"};var U=Te,je=Date.now||function(){return new Date().getTime()},ee=[],K=void 0,B=1,V=2,Q=new F,le=new F,ue=function(){function e(t,o,s,u){this._instanceConstructor=t,this.promise=new t(C,u),this._abortOnReject=s,this._init.apply(this,arguments)}return e.prototype._init=function(t,o){var s=o.length||0;this.length=s,this._remaining=s,this._result=new Array(s),this._enumerate(o),this._remaining===0&&_(this.promise,this._result)},e.prototype._enumerate=function(t){for(var o=this.length,s=this.promise,u=0;s._state===K&&u<o;u++)this._eachEntry(t[u],u)},e.prototype._settleMaybeThenable=function(t,o){var s=this._instanceConstructor,u=s.resolve;if(u===v){var f=R(t);if(f===I&&t._state!==K)t._onError=null,this._settledAt(t._state,o,t._result);else if(typeof f!="function")this._remaining--,this._result[o]=this._makeResult(B,o,t);else if(s===w){var y=new s(C);x(y,t,f),this._willSettleAt(y,o)}else this._willSettleAt(new s(function(P){return P(t)}),o)}else this._willSettleAt(u(t),o)},e.prototype._eachEntry=function(t,o){d(t)?this._settleMaybeThenable(t,o):(this._remaining--,this._result[o]=this._makeResult(B,o,t))},e.prototype._settledAt=function(t,o,s){var u=this.promise;u._state===K&&(this._abortOnReject&&t===V?O(u,s):(this._remaining--,this._result[o]=this._makeResult(t,o,s),this._remaining===0&&_(u,this._result)))},e.prototype._makeResult=function(t,o,s){return s},e.prototype._willSettleAt=function(t,o){var s=this;L(t,void 0,function(u){return s._settledAt(B,o,u)},function(u){return s._settledAt(V,o,u)})},e}(),dt="rsvp_"+je()+"-",ft=0,w=function(){function e(t,o){this._id=ft++,this._label=o,this._state=void 0,this._result=void 0,this._subscribers=[],E.instrument&&p("created",this),C!==t&&(typeof t!="function"&&Ue(),this instanceof e?z(this,t):Ve())}return e.prototype._onError=function(t){var o=this;E.after(function(){o._onError&&E.trigger("error",t,o._label)})},e.prototype.catch=function(t,o){return this.then(void 0,t,o)},e.prototype.finally=function(t,o){var s=this,u=s.constructor;return s.then(function(f){return u.resolve(t()).then(function(){return f})},function(f){return u.resolve(t()).then(function(){throw f})},o)},e}();w.cast=v,w.all=ne,w.race=G,w.resolve=v,w.reject=Xe,w.prototype._guidKey=dt,w.prototype.then=I;var q=new pe,Ne=new pe,Pe=function(e){function t(o,s,u){return Ze(this,e.call(this,o,s,!1,u))}return et(t,e),t}(ue);Pe.prototype._makeResult=X;var ht=Object.prototype.hasOwnProperty,Le=function(e){function t(o,s){var u=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2],f=arguments[3];return tt(this,e.call(this,o,s,u,f))}return nt(t,e),t.prototype._init=function(o,s){this._result={},this._enumerate(s),this._remaining===0&&_(this.promise,this._result)},t.prototype._enumerate=function(o){var s=this.promise,u=[];for(var f in o)ht.call(o,f)&&u.push({position:f,entry:o[f]});var y=u.length;this._remaining=y;for(var P=void 0,A=0;s._state===K&&A<y;A++)P=u[A],this._eachEntry(P.entry,P.position)},t}(ue),Ae=function(e){function t(o,s,u){return rt(this,e.call(this,o,s,!1,u))}return ot(t,e),t}(Le);Ae.prototype._makeResult=X;var Z=0,de=void 0,Me=typeof window!="undefined"?window:void 0,De=Me||{},$e=De.MutationObserver||De.WebKitMutationObserver,pt=typeof self=="undefined"&&typeof process!="undefined"&&{}.toString.call(process)==="[object process]",mt=typeof Uint8ClampedArray!="undefined"&&typeof importScripts!="undefined"&&typeof MessageChannel!="undefined",J=new Array(1e3),Be=void 0;if(Be=pt?st():$e?ct():mt?lt():Me===void 0&&typeof require=="function"?ut():se(),typeof self!="object"){if(typeof global!="object")throw new Error("no global: `self` or `global` found");global}var te;E.async=ie,E.after=function(e){return setTimeout(e,0)};var Ie=re,Fe=function(e,t){return E.async(e,t)};if(typeof window!="undefined"&&typeof window.__PROMISE_INSTRUMENTATION__=="object"){var fe=window.__PROMISE_INSTRUMENTATION__;c("instrument",!0);for(var he in fe)fe.hasOwnProperty(he)&&ae(he,fe[he])}var vt=(te={asap:ie,cast:Ie,Promise:w,EventTarget:ce,all:ye,allSettled:ge,race:we,hash:ke,hashSettled:Ce,rethrow:_e,defer:be,denodeify:ve,configure:c,on:ae,off:Re,resolve:re,reject:Ee,map:xe},Oe(te,"async",Fe),Oe(te,"filter",Se),te);n.default=vt,n.asap=ie,n.cast=Ie,n.Promise=w,n.EventTarget=ce,n.all=ye,n.allSettled=ge,n.race=we,n.hash=ke,n.hashSettled=Ce,n.rethrow=_e,n.defer=be,n.denodeify=ve,n.configure=c,n.on=ae,n.off=Re,n.resolve=re,n.reject=Ee,n.map=xe,n.async=Fe,n.filter=Se,Object.defineProperty(n,"__esModule",{value:!0})});var EPUBJS=EPUBJS||{};EPUBJS.core={};var ELEMENT_NODE=1,TEXT_NODE=3,COMMENT_NODE=8,DOCUMENT_NODE=9;EPUBJS.core.getEl=function(n){return document.getElementById(n)},EPUBJS.core.getEls=function(n){return document.getElementsByClassName(n)},EPUBJS.core.request=function(n,r,i){var c,a=window.URL,l=a?"blob":"arraybuffer",h=new RSVP.defer,d=new XMLHttpRequest,m=XMLHttpRequest.prototype,p=function(){var v;this.readyState==this.DONE&&(this.status!==200&&this.status!==0||!this.response?h.reject({message:this.response,stack:new Error().stack}):(v=r=="xml"?this.responseXML?this.responseXML:new DOMParser().parseFromString(this.response,"application/xml"):r=="xhtml"?this.responseXML?this.responseXML:new DOMParser().parseFromString(this.response,"application/xhtml+xml"):r=="html"?this.responseXML?this.responseXML:new DOMParser().parseFromString(this.response,"text/html"):r=="json"?JSON.parse(this.response):r=="blob"?a?this.response:new Blob([this.response]):this.response,h.resolve(v)))};return"overrideMimeType"in m||Object.defineProperty(m,"overrideMimeType",{value:function(v){}}),d.onreadystatechange=p,d.open("GET",n,!0),i&&(d.withCredentials=!0),r||(c=EPUBJS.core.uri(n),r=c.extension,r={htm:"html"}[r]||r),r=="blob"&&(d.responseType=l),r=="json"&&d.setRequestHeader("Accept","application/json"),r=="xml"&&(d.responseType="document",d.overrideMimeType("text/xml")),r=="xhtml"&&(d.responseType="document"),r=="html"&&(d.responseType="document"),r=="binary"&&(d.responseType="arraybuffer"),d.send(),h.promise},EPUBJS.core.toArray=function(n){var r=[];for(var i in n){var c;n.hasOwnProperty(i)&&(c=n[i],c.ident=i,r.push(c))}return r},EPUBJS.core.uri=function(n){var r,i,c,a={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:n},l=n.indexOf("blob:"),h=n.indexOf("://"),d=n.indexOf("?"),m=n.indexOf("#");return l===0?(a.protocol="blob",a.base=n.indexOf(0,m),a):(m!=-1&&(a.fragment=n.slice(m+1),n=n.slice(0,m)),d!=-1&&(a.search=n.slice(d+1),n=n.slice(0,d),href=a.href),h!=-1?(a.protocol=n.slice(0,h),r=n.slice(h+3),c=r.indexOf("/"),c===-1?(a.host=a.path,a.path=""):(a.host=r.slice(0,c),a.path=r.slice(c)),a.origin=a.protocol+"://"+a.host,a.directory=EPUBJS.core.folder(a.path),a.base=a.origin+a.directory):(a.path=n,a.directory=EPUBJS.core.folder(n),a.base=a.directory),a.filename=n.replace(a.base,""),i=a.filename.lastIndexOf("."),i!=-1&&(a.extension=a.filename.slice(i+1)),a)},EPUBJS.core.folder=function(n){var r=n.lastIndexOf("/");return r==-1,n.slice(0,r+1)},EPUBJS.core.dataURLToBlob=function(n){var r,i,c,a,l,h=";base64,";if(n.indexOf(h)==-1)return r=n.split(","),i=r[0].split(":")[1],c=r[1],new Blob([c],{type:i});r=n.split(h),i=r[0].split(":")[1],c=window.atob(r[1]),a=c.length,l=new Uint8Array(a);for(var d=0;d<a;++d)l[d]=c.charCodeAt(d);return new Blob([l],{type:i})},EPUBJS.core.addScript=function(n,r,i){var c,a;a=!1,c=document.createElement("script"),c.type="text/javascript",c.async=!1,c.src=n,c.onload=c.onreadystatechange=function(){a||this.readyState&&this.readyState!="complete"||(a=!0,r&&r())},i=i||document.body,i.appendChild(c)},EPUBJS.core.addScripts=function(n,r,i){var c=n.length,a=0,l=function(){a++,c==a?r&&r():EPUBJS.core.addScript(n[a],l,i)};EPUBJS.core.addScript(n[a],l,i)},EPUBJS.core.addCss=function(n,r,i){var c,a;a=!1,c=document.createElement("link"),c.type="text/css",c.rel="stylesheet",c.href=n,c.onload=c.onreadystatechange=function(){a||this.readyState&&this.readyState!="complete"||(a=!0,r&&r())},i=i||document.body,i.appendChild(c)},EPUBJS.core.prefixed=function(n){var r=["Webkit","Moz","O","ms"],i=n[0].toUpperCase()+n.slice(1),c=r.length;if(document.documentElement.style[n]!==void 0)return n;for(var a=0;a<c;a++)if(document.documentElement.style[r[a]+i]!==void 0)return r[a]+i;return n},EPUBJS.core.resolveUrl=function(n,r){var i,c,a=[],l=EPUBJS.core.uri(r),h=n.split("/");return l.host?r:(h.pop(),c=r.split("/"),c.forEach(function(d){d===".."?h.pop():a.push(d)}),i=h.concat(a),i.join("/"))},EPUBJS.core.uuid=function(){var n=new Date().getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){var i=(n+16*Math.random())%16|0;return n=Math.floor(n/16),(r=="x"?i:7&i|8).toString(16)})},EPUBJS.core.insert=function(n,r,i){var c=EPUBJS.core.locationOf(n,r,i);return r.splice(c,0,n),c},EPUBJS.core.locationOf=function(n,r,i,c,a){var l,h=c||0,d=a||r.length,m=parseInt(h+(d-h)/2);return i||(i=function(p,v){return p>v?1:p<v?-1:(p=v)?0:void 0}),d-h<=0?m:(l=i(r[m],n),d-h==1?l>0?m:m+1:l===0?m:l===-1?EPUBJS.core.locationOf(n,r,i,m,d):EPUBJS.core.locationOf(n,r,i,h,m))},EPUBJS.core.indexOfSorted=function(n,r,i,c,a){var l,h=c||0,d=a||r.length,m=parseInt(h+(d-h)/2);return i||(i=function(p,v){return p>v?1:p<v?-1:(p=v)?0:void 0}),d-h<=0?-1:(l=i(r[m],n),d-h==1?l===0?m:-1:l===0?m:l===-1?EPUBJS.core.indexOfSorted(n,r,i,m,d):EPUBJS.core.indexOfSorted(n,r,i,h,m))},EPUBJS.core.queue=function(n){var r=[],i=n,c=function(l,h,d){return r.push({funcName:l,args:h,context:d}),r},a=function(){var l;r.length&&(l=r.shift(),i[l.funcName].apply(l.context||i,l.args))};return{enqueue:c,dequeue:a,flush:function(){for(;r.length;)a()},clear:function(){r=[]},length:function(){return r.length}}},EPUBJS.core.getElementXPath=function(n){return n&&n.id?'//*[@id="'+n.id+'"]':EPUBJS.core.getElementTreeXPath(n)},EPUBJS.core.getElementTreeXPath=function(n){var r,i,c,a,l=[],h=n.ownerDocument.documentElement.getAttribute("xmlns")==="http://www.w3.org/1999/xhtml";for(n.nodeType===Node.TEXT_NODE&&(r=EPUBJS.core.indexOfTextNode(n)+1,l.push("text()["+r+"]"),n=n.parentNode);n&&n.nodeType==1;n=n.parentNode){r=0;for(var d=n.previousSibling;d;d=d.previousSibling)d.nodeType!=Node.DOCUMENT_TYPE_NODE&&d.nodeName==n.nodeName&&++r;i=n.nodeName.toLowerCase(),c=h?"xhtml:"+i:i,a=r?"["+(r+1)+"]":"",l.splice(0,0,c+a)}return l.length?"./"+l.join("/"):null},EPUBJS.core.nsResolver=function(n){return{xhtml:"http://www.w3.org/1999/xhtml",epub:"http://www.idpf.org/2007/ops"}[n]||null},EPUBJS.core.cleanStringForXpath=function(n){var r=n.match(/[^'"]+|['"]/g);return r=r.map(function(i){return i==="'"?`"'"`:i==='"'?`'"'`:"'"+i+"'"}),"concat('',"+r.join(",")+")"},EPUBJS.core.indexOfTextNode=function(n){for(var r,i=n.parentNode,c=i.childNodes,a=-1,l=0;l<c.length&&(r=c[l],r.nodeType===Node.TEXT_NODE&&a++,r!=n);l++);return a},EPUBJS.core.defaults=function(n){for(var r=1,i=arguments.length;r<i;r++){var c=arguments[r];for(var a in c)n[a]===void 0&&(n[a]=c[a])}return n},EPUBJS.core.extend=function(n){return[].slice.call(arguments,1).forEach(function(r){r&&Object.getOwnPropertyNames(r).forEach(function(i){Object.defineProperty(n,i,Object.getOwnPropertyDescriptor(r,i))})}),n},EPUBJS.core.clone=function(n){return EPUBJS.core.isArray(n)?n.slice():EPUBJS.core.extend({},n)},EPUBJS.core.isElement=function(n){return!(!n||n.nodeType!=1)},EPUBJS.core.isNumber=function(n){return!isNaN(parseFloat(n))&&isFinite(n)},EPUBJS.core.isString=function(n){return typeof n=="string"||n instanceof String},EPUBJS.core.isArray=Array.isArray||function(n){return Object.prototype.toString.call(n)==="[object Array]"},EPUBJS.core.values=function(n){var r,i,c,a=-1;if(!n)return[];for(r=Object.keys(n),i=r.length,c=Array(i);++a<i;)c[a]=n[r[a]];return c},EPUBJS.core.indexOfNode=function(n,r){for(var i,c=n.parentNode,a=c.childNodes,l=-1,h=0;h<a.length&&(i=a[h],i.nodeType===r&&l++,i!=n);h++);return l},EPUBJS.core.indexOfTextNode=function(n){return EPUBJS.core.indexOfNode(n,TEXT_NODE)},EPUBJS.core.indexOfElementNode=function(n){return EPUBJS.core.indexOfNode(n,ELEMENT_NODE)};var EPUBJS=EPUBJS||{};EPUBJS.reader={},EPUBJS.reader.plugins={},function(n,r){var i=(n.ePubReader,n.ePubReader=function(c,a){return new EPUBJS.Reader(c,a)});typeof define=="function"&&define.amd?define(function(){return Reader}):typeof module!="undefined"&&module.exports&&(module.exports=i)}(window,jQuery),EPUBJS.Reader=function(n,r){var i,c,a,l=this,h=$("#viewer"),d=window.location.search;this.settings=EPUBJS.core.defaults(r||{},{bookPath:n,restore:!1,reload:!1,bookmarks:void 0,annotations:void 0,contained:void 0,bookKey:void 0,styles:void 0,sidebarReflow:!1,generatePagination:!1,history:!0}),d&&(a=d.slice(1).split("&"),a.forEach(function(m){var p=m.split("="),v=p[0],k=p[1]||"";l.settings[v]=decodeURIComponent(k)})),this.setBookKey(this.settings.bookPath),this.settings.restore&&this.isSaved()&&this.applySavedSettings(),this.settings.styles=this.settings.styles||{fontSize:"100%"},this.book=i=new ePub(this.settings.bookPath,this.settings),this.offline=!1,this.sidebarOpen=!1,this.settings.bookmarks||(this.settings.bookmarks=[]),this.settings.annotations||(this.settings.annotations=[]),this.settings.generatePagination&&i.generatePagination(h.width(),h.height()),this.rendition=i.renderTo("viewer",{ignoreClass:"annotator-hl",width:"100%",height:"100%"}),this.settings.previousLocationCfi?this.displayed=this.rendition.display(this.settings.previousLocationCfi):this.displayed=this.rendition.display(),i.ready.then(function(){l.ReaderController=EPUBJS.reader.ReaderController.call(l,i),l.SettingsController=EPUBJS.reader.SettingsController.call(l,i),l.ControlsController=EPUBJS.reader.ControlsController.call(l,i),l.SidebarController=EPUBJS.reader.SidebarController.call(l,i),l.BookmarksController=EPUBJS.reader.BookmarksController.call(l,i),l.NotesController=EPUBJS.reader.NotesController.call(l,i),window.addEventListener("hashchange",this.hashChanged.bind(this),!1),document.addEventListener("keydown",this.adjustFontSize.bind(this),!1),this.rendition.on("keydown",this.adjustFontSize.bind(this)),this.rendition.on("keydown",l.ReaderController.arrowKeys.bind(this)),this.rendition.on("selected",this.selectedRange.bind(this))}.bind(this)).then(function(){l.ReaderController.hideLoader()}.bind(this));for(c in EPUBJS.reader.plugins)EPUBJS.reader.plugins.hasOwnProperty(c)&&(l[c]=EPUBJS.reader.plugins[c].call(l,i));return i.loaded.metadata.then(function(m){l.MetaController=EPUBJS.reader.MetaController.call(l,m)}),i.loaded.navigation.then(function(m){l.TocController=EPUBJS.reader.TocController.call(l,m)}),window.addEventListener("beforeunload",this.unload.bind(this),!1),this},EPUBJS.Reader.prototype.adjustFontSize=function(n){var r,i=2,c=n.ctrlKey||n.metaKey;this.settings.styles&&(this.settings.styles.fontSize||(this.settings.styles.fontSize="100%"),r=parseInt(this.settings.styles.fontSize.slice(0,-1)),c&&n.keyCode==187&&(n.preventDefault(),this.book.setStyle("fontSize",r+i+"%")),c&&n.keyCode==189&&(n.preventDefault(),this.book.setStyle("fontSize",r-i+"%")),c&&n.keyCode==48&&(n.preventDefault(),this.book.setStyle("fontSize","100%")))},EPUBJS.Reader.prototype.addBookmark=function(n){this.isBookmarked(n)>-1||(this.settings.bookmarks.push(n),this.trigger("reader:bookmarked",n))},EPUBJS.Reader.prototype.removeBookmark=function(n){var r=this.isBookmarked(n);r!==-1&&(this.settings.bookmarks.splice(r,1),this.trigger("reader:unbookmarked",r))},EPUBJS.Reader.prototype.isBookmarked=function(n){return this.settings.bookmarks.indexOf(n)},EPUBJS.Reader.prototype.clearBookmarks=function(){this.settings.bookmarks=[]},EPUBJS.Reader.prototype.addNote=function(n){this.settings.annotations.push(n)},EPUBJS.Reader.prototype.removeNote=function(n){var r=this.settings.annotations.indexOf(n);r!==-1&&delete this.settings.annotations[r]},EPUBJS.Reader.prototype.clearNotes=function(){this.settings.annotations=[]},EPUBJS.Reader.prototype.setBookKey=function(n){return this.settings.bookKey||(this.settings.bookKey="epubjsreader:"+EPUBJS.VERSION+":"+window.location.host+":"+n),this.settings.bookKey},EPUBJS.Reader.prototype.isSaved=function(n){return!!localStorage&&localStorage.getItem(this.settings.bookKey)!==null},EPUBJS.Reader.prototype.removeSavedSettings=function(){if(!localStorage)return!1;localStorage.removeItem(this.settings.bookKey)},EPUBJS.Reader.prototype.applySavedSettings=function(){var n;if(!localStorage)return!1;try{n=JSON.parse(localStorage.getItem(this.settings.bookKey))}catch(r){return!1}return!!n&&(n.styles&&(this.settings.styles=EPUBJS.core.defaults(this.settings.styles||{},n.styles)),this.settings=EPUBJS.core.defaults(this.settings,n),!0)},EPUBJS.Reader.prototype.saveSettings=function(){if(this.book&&(this.settings.previousLocationCfi=this.rendition.currentLocation().start.cfi),!localStorage)return!1;localStorage.setItem(this.settings.bookKey,JSON.stringify(this.settings))},EPUBJS.Reader.prototype.unload=function(){this.settings.restore&&localStorage&&this.saveSettings()},EPUBJS.Reader.prototype.hashChanged=function(){var n=window.location.hash.slice(1);this.rendition.display(n)},EPUBJS.Reader.prototype.selectedRange=function(n){var r="#"+n;this.settings.history&&window.location.hash!=r&&(history.pushState({},"",r),this.currentLocationCfi=n)},RSVP.EventTarget.mixin(EPUBJS.Reader.prototype),EPUBJS.reader.BookmarksController=function(){var n=this.book,r=this.rendition,i=$("#bookmarksView"),c=i.find("#bookmarks"),a=document.createDocumentFragment(),l=function(){i.show()},h=function(){i.hide()},d=0,m=function(p){var v=document.createElement("li"),k=document.createElement("a");v.id="bookmark-"+d,v.classList.add("list_item");var C,R=n.spine.get(p);return R.index in n.navigation.toc?(C=n.navigation.toc[R.index],k.textContent=C.label):k.textContent=p,k.href=p,k.classList.add("bookmark_link"),k.addEventListener("click",function(j){var N=this.getAttribute("href");r.display(N),j.preventDefault()},!1),v.appendChild(k),d++,v};return this.settings.bookmarks.forEach(function(p){var v=m(p);a.appendChild(v)}),c.append(a),this.on("reader:bookmarked",function(p){var v=m(p);c.append(v)}),this.on("reader:unbookmarked",function(p){$("#bookmark-"+p).remove()}),{show:l,hide:h}},EPUBJS.reader.ControlsController=function(n){var r=this,i=this.rendition,c=($("#store"),$("#fullscreen")),a=($("#fullscreenicon"),$("#cancelfullscreenicon"),$("#slider")),l=($("#main"),$("#sidebar"),$("#setting")),h=$("#bookmark");return a.on("click",function(){r.sidebarOpen?(r.SidebarController.hide(),a.addClass("icon-menu"),a.removeClass("icon-right")):(r.SidebarController.show(),a.addClass("icon-right"),a.removeClass("icon-menu"))}),typeof screenfull!="undefined"&&(c.on("click",function(){screenfull.toggle($("#container")[0])}),screenfull.raw&&document.addEventListener(screenfull.raw.fullscreenchange,function(){fullscreen=screenfull.isFullscreen,fullscreen?c.addClass("icon-resize-small").removeClass("icon-resize-full"):c.addClass("icon-resize-full").removeClass("icon-resize-small")})),l.on("click",function(){r.SettingsController.show()}),h.on("click",function(){var d=r.rendition.currentLocation().start.cfi;r.isBookmarked(d)===-1?(r.addBookmark(d),h.addClass("icon-bookmark").removeClass("icon-bookmark-empty")):(r.removeBookmark(d),h.removeClass("icon-bookmark").addClass("icon-bookmark-empty"))}),i.on("relocated",function(d){var m=d.start.cfi,p="#"+m;r.isBookmarked(m)===-1?h.removeClass("icon-bookmark").addClass("icon-bookmark-empty"):h.addClass("icon-bookmark").removeClass("icon-bookmark-empty"),r.currentLocationCfi=m,r.settings.history&&window.location.hash!=p&&history.pushState({},"",p)}),{}},EPUBJS.reader.MetaController=function(n){var r=n.title,i=n.creator,c=$("#book-title"),a=$("#chapter-title"),l=$("#title-seperator");document.title=r+" \u2013 "+i,c.html(r),a.html(i),l.show()},EPUBJS.reader.NotesController=function(){var n=this.book,r=this.rendition,i=this,c=$("#notesView"),a=$("#notes"),l=$("#note-text"),h=$("#note-anchor"),d=i.settings.annotations,m=n.renderer,p=[],v=new ePub.CFI,k=function(){c.show()},C=function(){c.hide()},R=function(x){var b,g,_,O,L,D=n.renderer.doc;if(D.caretPositionFromPoint?(b=D.caretPositionFromPoint(x.clientX,x.clientY),g=b.offsetNode,_=b.offset):D.caretRangeFromPoint&&(b=D.caretRangeFromPoint(x.clientX,x.clientY),g=b.startContainer,_=b.startOffset),g.nodeType!==3){for(var F=0;F<g.childNodes.length;F++)if(g.childNodes[F].nodeType==3){g=g.childNodes[F];break}}_=g.textContent.indexOf(".",_),_===-1?_=g.length:_+=1,O=v.generateCfiFromTextNode(g,_,n.renderer.currentChapter.cfiBase),L={annotatedAt:new Date,anchor:O,body:l.val()},i.addNote(L),j(L),N(L),l.val(""),h.text("Attach"),l.prop("disabled",!1),r.off("click",R)},j=function(x){var b=document.createElement("li"),g=document.createElement("a");b.innerHTML=x.body,g.innerHTML=" context &#187;",g.href="#"+x.anchor,g.onclick=function(){return r.display(x.anchor),!1},b.appendChild(g),a.append(b)},N=function(x){var b=n.renderer.doc,g=document.createElement("span"),_=document.createElement("a");g.classList.add("footnotesuperscript","reader_generated"),g.style.verticalAlign="super",g.style.fontSize=".75em",g.style.lineHeight="1em",_.style.padding="2px",_.style.backgroundColor="#fffa96",_.style.borderRadius="5px",_.style.cursor="pointer",g.id="note-"+EPUBJS.core.uuid(),_.innerHTML=d.indexOf(x)+1+"[Reader]",g.appendChild(_),v.addMarker(x.anchor,b,g),S(g,x.body)},S=function(x,b){var g=x.id,_=function(){var T,H,z,I,X=m.height,ne=m.width,G=225;p[g]||(p[g]=document.createElement("div"),p[g].setAttribute("class","popup"),pop_content=document.createElement("div"),p[g].appendChild(pop_content),pop_content.innerHTML=b,pop_content.setAttribute("class","pop_content"),m.render.document.body.appendChild(p[g]),p[g].addEventListener("mouseover",O,!1),p[g].addEventListener("mouseout",L,!1),r.on("locationChanged",D,this),r.on("locationChanged",L,this)),T=p[g],H=x.getBoundingClientRect(),z=H.left,I=H.top,T.classList.add("show"),popRect=T.getBoundingClientRect(),T.style.left=z-popRect.width/2+"px",T.style.top=I+"px",G>X/2.5&&(G=X/2.5,pop_content.style.maxHeight=G+"px"),popRect.height+I>=X-25?(T.style.top=I-popRect.height+"px",T.classList.add("above")):T.classList.remove("above"),z-popRect.width<=0?(T.style.left=z+"px",T.classList.add("left")):T.classList.remove("left"),z+popRect.width/2>=ne?(T.style.left=z-300+"px",popRect=T.getBoundingClientRect(),T.style.left=z-popRect.width+"px",popRect.height+I>=X-25?(T.style.top=I-popRect.height+"px",T.classList.add("above")):T.classList.remove("above"),T.classList.add("right")):T.classList.remove("right")},O=function(){p[g].classList.add("on")},L=function(){p[g].classList.remove("on")},D=function(){setTimeout(function(){p[g].classList.remove("show")},100)},F=function(){i.ReaderController.slideOut(),k()};x.addEventListener("mouseover",_,!1),x.addEventListener("mouseout",D,!1),x.addEventListener("click",F,!1)};return h.on("click",function(x){h.text("Cancel"),l.prop("disabled","true"),r.on("click",R)}),d.forEach(function(x){j(x)}),{show:k,hide:C}},EPUBJS.reader.ReaderController=function(n){var r=$("#main"),i=$("#divider"),c=$("#loader"),a=$("#next"),l=$("#prev"),h=this,n=this.book,d=this.rendition,m=function(){d.currentLocation().start.cfi,h.settings.sidebarReflow?(r.removeClass("single"),r.one("transitionend",function(){d.resize()})):r.removeClass("closed")},p=function(){var S=d.currentLocation();S&&(S.start.cfi,h.settings.sidebarReflow?(r.addClass("single"),r.one("transitionend",function(){d.resize()})):r.addClass("closed"))},v=function(){c.show(),R()},k=function(){c.hide()},C=function(){i.addClass("show")},R=function(){i.removeClass("show")},j=!1,N=function(S){S.keyCode==37&&(n.package.metadata.direction==="rtl"?d.next():d.prev(),l.addClass("active"),j=!0,setTimeout(function(){j=!1,l.removeClass("active")},100),S.preventDefault()),S.keyCode==39&&(n.package.metadata.direction==="rtl"?d.prev():d.next(),a.addClass("active"),j=!0,setTimeout(function(){j=!1,a.removeClass("active")},100),S.preventDefault())};return document.addEventListener("keydown",N,!1),a.on("click",function(S){n.package.metadata.direction==="rtl"?d.prev():d.next(),S.preventDefault()}),l.on("click",function(S){n.package.metadata.direction==="rtl"?d.next():d.prev(),S.preventDefault()}),d.on("layout",function(S){S.spread===!0?C():R()}),d.on("relocated",function(S){S.atStart&&l.addClass("disabled"),S.atEnd&&a.addClass("disabled")}),{slideOut:p,slideIn:m,showLoader:v,hideLoader:k,showDivider:C,hideDivider:R,arrowKeys:N}},EPUBJS.reader.SettingsController=function(){var n=(this.book,this),r=$("#settings-modal"),i=$(".overlay"),c=function(){r.addClass("md-show")},a=function(){r.removeClass("md-show")};return $("#sidebarReflow").on("click",function(){n.settings.sidebarReflow=!n.settings.sidebarReflow}),r.find(".closer").on("click",function(){a()}),i.on("click",function(){a()}),{show:c,hide:a}},EPUBJS.reader.SidebarController=function(n){var r=this,i=$("#sidebar"),c=$("#panels"),a="Toc",l=function(p){var v=p+"Controller";a!=p&&r[v]!==void 0&&(r[a+"Controller"].hide(),r[v].show(),a=p,c.find(".active").removeClass("active"),c.find("#show-"+p).addClass("active"))},h=function(){return a},d=function(){r.sidebarOpen=!0,r.ReaderController.slideOut(),i.addClass("open")},m=function(){r.sidebarOpen=!1,r.ReaderController.slideIn(),i.removeClass("open")};return c.find(".show_view").on("click",function(p){var v=$(this).data("view");l(v),p.preventDefault()}),{show:d,hide:m,getActivePanel:h,changePanelTo:l}},EPUBJS.reader.TocController=function(n){var r=(this.book,this.rendition),i=$("#tocView"),c=document.createDocumentFragment(),a=!1,l=function(v,k){var C=document.createElement("ul");return k||(k=1),v.forEach(function(R){var j=document.createElement("li"),N=document.createElement("a");toggle=document.createElement("a");var S;j.id="toc-"+R.id,j.classList.add("list_item"),N.textContent=R.label,N.href=R.href,N.classList.add("toc_link"),j.appendChild(N),R.subitems&&R.subitems.length>0&&(k++,S=l(R.subitems,k),toggle.classList.add("toc_toggle"),j.insertBefore(toggle,N),j.appendChild(S)),C.appendChild(j)}),C},h=function(){i.show()},d=function(){i.hide()},m=function(v){var k=v.id,C=i.find("#toc-"+k),R=i.find(".currentChapter");i.find(".openChapter"),C.length&&(C!=R&&C.has(a).length>0&&R.removeClass("currentChapter"),C.addClass("currentChapter"),C.parents("li").addClass("openChapter"))};r.on("renderered",m);var p=l(n);return c.appendChild(p),i.append(c),i.find(".toc_link").on("click",function(v){var k=this.getAttribute("href");v.preventDefault(),r.display(k),i.find(".currentChapter").addClass("openChapter").removeClass("currentChapter"),$(this).parent("li").addClass("currentChapter")}),i.find(".toc_toggle").on("click",function(v){var k=$(this).parent("li"),C=k.hasClass("openChapter");v.preventDefault(),C?k.removeClass("openChapter"):k.addClass("openChapter")}),{show:h,hide:d}};