"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[52590],{68352:function(t,e,i){i.r(e),i.d(e,{Book:function(){return es},Contents:function(){return Ci},EpubCFI:function(){return ft},Layout:function(){return ai},Rendition:function(){return Pn},default:function(){return ns}});var n={};i.r(n),i.d(n,{RangeObject:function(){return G},blob2base64:function(){return V},borders:function(){return E},bounds:function(){return C},createBase64Url:function(){return q},createBlob:function(){return R},createBlobUrl:function(){return N},defaults:function(){return w},defer:function(){return X},documentHeight:function(){return v},extend:function(){return k},filterChildren:function(){return Z},findChildren:function(){return J},getParentByTagName:function(){return $},indexOfElementNode:function(){return j},indexOfNode:function(){return _},indexOfSorted:function(){return T},indexOfTextNode:function(){return O},insert:function(){return x},isElement:function(){return y},isFloat:function(){return g},isNumber:function(){return m},isXml:function(){return z},locationOf:function(){return S},nodeBounds:function(){return P},parents:function(){return Q},parse:function(){return A},prefixed:function(){return b},qs:function(){return M},qsa:function(){return W},qsp:function(){return F},querySelectorByType:function(){return Y},requestAnimationFrame:function(){return u},revokeBlobUrl:function(){return B},sprint:function(){return U},treeWalker:function(){return D},type:function(){return I},uuid:function(){return p},walk:function(){return H},windowBounds:function(){return L}}),i(29305),i(32733),i(84701),i(81678),i(24776),i(84734),i(44962),i(66781),i(74455),i(4754),i(94),i(36947),i(78557),i(90076),i(95021),i(73687),i(83994),i(93062),i(82367);var s=i(31464),r=i.n(s),o=(i(14382),i(89336),i(74576),i(13225),i(36457),i(40718),i(67593),i(96054),i(23630),i(24362),i(76218),i(99102),i(32854));function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}function h(t,e){for(var i=0;i-1||Math.floor(e)!==e)}function b(t){var e=["-webkit-","-webkit-","-moz-","-o-","-ms-"],i=t.toLowerCase();if("undefined"==typeof document||void 0!==document.body.style[i])return t;for(var n=0;n<5;n++)if(void 0!==document.body.style[e[n]+i])return e[n]+i;return t}function w(t){for(var e=1,i=arguments.length;ee?1:t=0?h:h+1:0===r?h:-1===r?S(t,e,i,h,a):S(t,e,i,o,h))}function T(t,e,i,n,s){var r,o=n||0,a=s||e.length,h=parseInt(o+(a-o)/2);return i||(i=function(t,e){return t>e?1:t-1}function R(t,e){return new Blob([t],{type:e})}function N(t,e){var i=R(t,e);return f.createObjectURL(i)}function B(t){return f.revokeObjectURL(t)}function q(t,e){if("string"==typeof t)return"data:"+e+";base64,"+btoa(t)}function I(t){return Object.prototype.toString.call(t).slice(8,-1)}function A(t,e,i){var n;return n="undefined"==typeof DOMParser||i?o.DOMParser:DOMParser,65279===t.charCodeAt(0)&&(t=t.slice(1)),(new n).parseFromString(t,e)}function M(t,e){var i;if(!t)throw new Error("No Element Provided");return void 0!==t.querySelector?t.querySelector(e):(i=t.getElementsByTagName(e)).length?i[0]:void 0}function W(t,e){return void 0!==t.querySelector?t.querySelectorAll(e):t.getElementsByTagName(e)}function F(t,e,i){var n,s;if(void 0!==t.querySelector){for(var r in e+="[",i)e+=r+"~='"+i[r]+"'";return e+="]",t.querySelector(e)}if(n=t.getElementsByTagName(e),s=Array.prototype.slice.call(n,0).filter((function(t){for(var e in i)if(t.getAttribute(e)===i[e])return!0;return!1})),s)return s[0]}function U(t,e){void 0!==(t.ownerDocument||t).createTreeWalker?D(t,e,NodeFilter.SHOW_TEXT):H(t,(function(t){t&&3===t.nodeType&&e(t)}))}function D(t,e,i){for(var n,s=document.createTreeWalker(t,i,null,!1);n=s.nextNode();)e(n)}function H(t,e){if(e(t))return!0;if(t=t.firstChild)do{if(H(t,e))return!0;t=t.nextSibling}while(t)}function V(t){return new Promise((function(e,i){var n=new FileReader;n.readAsDataURL(t),n.onloadend=function(){e(n.result)}}))}function X(){var t=this;this.resolve=null,this.reject=null,this.id=p(),this.promise=new Promise((function(e,i){t.resolve=e,t.reject=i})),Object.freeze(this)}function Y(t,e,i){var n;if(void 0!==t.querySelector&&(n=t.querySelector("".concat(e,'[*|type="').concat(i,'"]'))),n&&0!==n.length)return n;n=W(t,e);for(var s=0;s-1&&(e=new URL(e).pathname),i=this.parse(e),this.path=e,this.isDirectory(e)?this.directory=e:this.directory=i.dir+"/",this.filename=i.base,this.extension=i.ext.slice(1)},(e=[{key:"parse",value:function(t){return tt().parse(t)}},{key:"isAbsolute",value:function(t){return tt().isAbsolute(t||this.path)}},{key:"isDirectory",value:function(t){return"/"===t.charAt(t.length-1)}},{key:"resolve",value:function(t){return tt().resolve(this.directory,t)}},{key:"relative",value:function(t){return t&&t.indexOf("://")>-1?t:tt().relative(this.directory,t)}},{key:"splitPath",value:function(t){return this.splitPathRe.exec(t).slice(1)}},{key:"toString",value:function(){return this.path}}])&&it(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function rt(t){return rt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},rt(t)}function ot(t,e){for(var i=0;i-1,s=e;if(this.Url=void 0,this.href=e,this.protocol="",this.origin="",this.hash="",this.hash="",this.search="",this.base=i,!n&&!1!==i&&"string"!=typeof i&&window&&window.location&&(this.base=window.location.href),n||this.base)try{this.base?this.Url=new URL(e,this.base):this.Url=new URL(e),this.href=this.Url.href,this.protocol=this.Url.protocol,this.origin=this.Url.origin,this.hash=this.Url.hash,this.search=this.Url.search,s=this.Url.pathname+(this.Url.search?this.Url.search:"")}catch(t){this.Url=void 0,this.base&&(s=new st(this.base).resolve(s))}this.Path=new st(s),this.directory=this.Path.directory,this.filename=this.Path.filename,this.extension=this.Path.extension},(e=[{key:"path",value:function(){return this.Path}},{key:"resolve",value:function(t){var e;return t.indexOf("://")>-1?t:(e=tt().resolve(this.directory,t),this.origin+e)}},{key:"relative",value:function(t){return tt().relative(t,this.directory)}},{key:"toString",value:function(){return this.href}}])&&ot(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function lt(t){return lt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},lt(t)}function ut(t,e){for(var i=0;i1&&(e=n[1],i.terminal=this.parseTerminal(e)),""===s[0]&&s.shift(),i.steps=s.map(function(t){return this.parseStep(t)}.bind(this)),i}},{key:"parseStep",value:function(t){var e,i,n,s,r;if((s=t.match(/\[(.*)\]/))&&s[1]&&(r=s[1]),i=parseInt(t),!isNaN(i))return i%2==0?(e="element",n=i/2-1):(e="text",n=(i-1)/2),{type:e,index:n,id:r||null}}},{key:"parseTerminal",value:function(t){var e,i,n=t.match(/\[(.*)\]/);return n&&n[1]?(e=parseInt(t.split("[")[0]),i=n[1]):e=parseInt(t),m(e)||(e=null),{offset:e,assertion:i}}},{key:"getChapterComponent",value:function(t){return t.split("!")[0]}},{key:"getPathComponent",value:function(t){var e=t.split("!");if(e[1])return e[1].split(",")[0]}},{key:"getRange",value:function(t){var e=t.split(",");return 3===e.length&&[e[1],e[2]]}},{key:"getCharecterOffsetComponent",value:function(t){return t.split(":")[1]||""}},{key:"joinSteps",value:function(t){return t?t.map((function(t){var e="";return"element"===t.type&&(e+=2*(t.index+1)),"text"===t.type&&(e+=1+2*t.index),t.id&&(e+="["+t.id+"]"),e})).join("/"):""}},{key:"segmentString",value:function(t){var e="/";return e+=this.joinSteps(t.steps),t.terminal&&null!=t.terminal.offset&&(e+=":"+t.terminal.offset),t.terminal&&null!=t.terminal.assertion&&(e+="["+t.terminal.assertion+"]"),e}},{key:"toString",value:function(){var t="epubcfi(";return t+=this.segmentString(this.base),t+="!",t+=this.segmentString(this.path),this.range&&this.start&&(t+=",",t+=this.segmentString(this.start)),this.range&&this.end&&(t+=",",t+=this.segmentString(this.end)),t+")"}},{key:"compare",value:function(e,i){var n,s,r,o;if("string"==typeof e&&(e=new t(e)),"string"==typeof i&&(i=new t(i)),e.spinePos>i.spinePos)return 1;if(e.spinePoss[a].index)return 1;if(n[a].indexo.offset?1:r.offset=0&&(s.terminal.offset=e,"text"!=s.steps[s.steps.length-1].type&&s.steps.push({type:"text",index:0})),s}},{key:"equalStep",value:function(t,e){return!(!t||!e)&&t.index===e.index&&t.id===e.id&&t.type===e.type}},{key:"fromRange",value:function(t,e,i){var n={range:!1,base:{},path:{},start:null,end:null},s=t.startContainer,r=t.endContainer,o=t.startOffset,a=t.endOffset,h=!1;if(i&&(h=null!=s.ownerDocument.querySelector("."+i)),"string"==typeof e?(n.base=this.parseComponent(e),n.spinePos=n.base.steps[1].index):"object"===lt(e)&&(n.base=e),t.collapsed)h&&(o=this.patchOffset(s,o,i)),n.path=this.pathTo(s,o,i);else{n.range=!0,h&&(o=this.patchOffset(s,o,i)),n.start=this.pathTo(s,o,i),h&&(a=this.patchOffset(r,a,i)),n.end=this.pathTo(r,a,i),n.path={steps:[],terminal:null};var l,u=n.start.steps.length;for(l=0;l0&&3===s&&3===r?o[n]=a:e===s&&(a+=1,o[n]=a),r=s;return o}},{key:"position",value:function(t){var e,i;return 1===t.nodeType?((e=t.parentNode.children)||(e=J(t.parentNode)),i=Array.prototype.indexOf.call(e,t)):i=(e=this.textNodes(t.parentNode)).indexOf(t),i}},{key:"filteredPosition",value:function(t,e){var i,n;return 1===t.nodeType?(i=t.parentNode.children,n=this.normalizedMap(i,1,e)):(i=t.parentNode.childNodes,t.parentNode.classList.contains(e)&&(i=(t=t.parentNode).parentNode.childNodes),n=this.normalizedMap(i,3,e)),n[Array.prototype.indexOf.call(i,t)]}},{key:"stepsToXpath",value:function(t){var e=[".","*"];return t.forEach((function(t){var i=t.index+1;t.id?e.push("*[position()="+i+" and @id='"+t.id+"']"):"text"===t.type?e.push("text()["+i+"]"):e.push("*["+i+"]")})),e.join("/")}},{key:"stepsToQuerySelector",value:function(t){var e=["html"];return t.forEach((function(t){var i=t.index+1;t.id?e.push("#"+t.id):"text"===t.type||e.push("*:nth-child("+i+")")})),e.join(">")}},{key:"textNodes",value:function(t,e){return Array.prototype.slice.call(t.childNodes).filter((function(t){return 3===t.nodeType||!(!e||!t.classList.contains(e))}))}},{key:"walkToNode",value:function(t,e,i){var n,s,r=e||document,o=r.documentElement,a=t.length;for(s=0;s(r=(s=a[u]).textContent.length))){o=1===s.nodeType?s.childNodes[0]:s;break}e-=r}}return{container:o,offset:e}}},{key:"toRange",value:function(t,e){var i,n,s,r,o,a,h,l,u=t||document,c=this,d=!!e&&null!=u.querySelector("."+e);if(i=void 0!==u.createRange?u.createRange():new G,c.range?(n=c.start,a=c.path.steps.concat(n.steps),r=this.findNode(a,u,d?e:null),s=c.end,h=c.path.steps.concat(s.steps),o=this.findNode(h,u,d?e:null)):(n=c.path,a=c.path.steps,r=this.findNode(c.path.steps,u,d?e:null)),!r)return console.log("No startContainer found for",this.toString()),null;try{null!=n.terminal.offset?i.setStart(r,n.terminal.offset):i.setStart(r,0)}catch(t){l=this.fixMiss(a,n.terminal.offset,u,d?e:null),i.setStart(l.container,l.offset)}if(o)try{null!=s.terminal.offset?i.setEnd(o,s.terminal.offset):i.setEnd(o,0)}catch(t){l=this.fixMiss(h,c.end.terminal.offset,u,d?e:null),i.setEnd(l.container,l.offset)}return i}},{key:"isCfiString",value:function(t){return"string"==typeof t&&0===t.indexOf("epubcfi(")&&")"===t[t.length-1]}},{key:"generateChapterComponent",value:function(t,e,i){var n="/"+2*(t+1)+"/";return n+=2*(parseInt(e)+1),i&&(n+="["+i+"]"),n}},{key:"collapse",value:function(t){this.range&&(this.range=!1,t?(this.path.steps=this.path.steps.concat(this.start.steps),this.path.terminal=this.start.terminal):(this.path.steps=this.path.steps.concat(this.end.steps),this.path.terminal=this.end.terminal))}}],i&&ut(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,i}(),ft=dt;function pt(t){return pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},pt(t)}function vt(t,e){for(var i=0;i-1;t&&(n=M(t,"head"),(i=M(n,"base"))||(i=t.createElement("base"),n.insertBefore(i,n.firstChild)),!r&&window&&window.location&&(s=window.location.origin+s),i.setAttribute("href",s))}function wt(t,e){var i,n,s=e.canonical;t&&(i=M(t,"head"),(n=M(i,"link[rel='canonical']"))?n.setAttribute("href",s):((n=t.createElement("link")).setAttribute("rel","canonical"),n.setAttribute("href",s),i.appendChild(n)))}function kt(t,e){var i,n,s=e.idref;t&&(i=M(t,"head"),(n=M(i,"link[property='dc.identifier']"))?n.setAttribute("content",s):((n=t.createElement("meta")).setAttribute("name","dc.identifier"),n.setAttribute("content",s),i.appendChild(n)))}function xt(t,e,i){return e.forEach((function(e,n){e&&i[n]&&(e=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),t=t.replace(new RegExp(e,"g"),i[n]))})),t}i(69703),i(20518),i(646),i(83810);var St=function(t,e,i,n){var s,r="undefined"!=typeof window&&window.URL,o=r?"blob":"arraybuffer",a=new X,h=new XMLHttpRequest,l=XMLHttpRequest.prototype;for(s in"overrideMimeType"in l||Object.defineProperty(l,"overrideMimeType",{value:function(){}}),i&&(h.withCredentials=!0),h.onreadystatechange=function(){if(this.readyState===XMLHttpRequest.DONE){var t=!1;if(""!==this.responseType&&"document"!==this.responseType||(t=this.responseXML),200===this.status||0===this.status||t){var i;if(!this.response&&!t)return a.reject({status:this.status,message:"Empty Response",stack:(new Error).stack}),a.promise;if(403===this.status)return a.reject({status:this.status,response:this.response,message:"Forbidden",stack:(new Error).stack}),a.promise;i=t?this.responseXML:z(e)?A(this.response,"text/xml"):"xhtml"==e?A(this.response,"application/xhtml+xml"):"html"==e||"htm"==e?A(this.response,"text/html"):"json"==e?JSON.parse(this.response):"blob"==e?r?this.response:new Blob([this.response]):this.response,a.resolve(i)}else a.reject({status:this.status,message:this.response,stack:(new Error).stack})}},h.onerror=function(t){a.reject(t)},h.open("GET",t,!0),n)h.setRequestHeader(s,n[s]);return"json"==e&&h.setRequestHeader("Accept","application/json"),e||(e=new st(t).extension),"blob"==e&&(h.responseType=o),z(e)&&h.overrideMimeType("text/xml"),"binary"==e&&(h.responseType="arraybuffer"),h.send(),a.promise};function Tt(t){return Tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Tt(t)}function Ct(t,e){for(var i=0;i=0,i=new("undefined"==typeof XMLSerializer||e?o.DOMParser:XMLSerializer);return this.output=i.serializeToString(t),this.output}.bind(this)).then(function(){return this.hooks.serialize.trigger(this.output,this)}.bind(this)).then(function(){e.resolve(this.output)}.bind(this)).catch((function(t){e.reject(t)})),i}},{key:"find",value:function(t){var e=this,i=[],n=t.toLowerCase();return U(e.document,(function(t){!function(t){for(var s,r,o,a=t.textContent.toLowerCase(),h=e.document.createRange(),l=-1;-1!=r;)-1!=(r=a.indexOf(n,l+1))&&((h=e.document.createRange()).setStart(t,r),h.setEnd(t,r+n.length),s=e.cfiFromRange(h),o=t.textContent.length<150?t.textContent:"..."+(o=t.textContent.substring(r-75,r+75))+"...",i.push({cfi:s,excerpt:o})),l=r}(t)})),i}},{key:"search",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;if(void 0===document.createTreeWalker)return this.find(t);for(var i,n=[],s=this,r=t.toLowerCase(),o=function(t){var e=t.reduce((function(t,e){return t+e.textContent}),"").toLowerCase().indexOf(r);if(-1!=e){var i=e+r.length,o=0,a=0;if(ei?i:i-d),h=s.cfiFromRange(c);var f=t.slice(0,o+1).reduce((function(t,e){return t+e.textContent}),"");f.length>150&&(f="..."+(f=f.substring(e-75,e+75))+"..."),n.push({cfi:h,excerpt:f})}}},a=document.createTreeWalker(s.document,NodeFilter.SHOW_TEXT,null,!1),h=[];i=a.nextNode();)h.push(i),h.length==e&&(o(h.slice(0,e)),h=h.slice(1,e));return h.length>0&&o(h),n}},{key:"reconcileLayoutSettings",value:function(t){var e={layout:t.layout,spread:t.spread,orientation:t.orientation};return this.properties.forEach((function(t){var i,n,s=t.replace("rendition:",""),r=s.indexOf("-");-1!=r&&(i=s.slice(0,r),n=s.slice(r+1),e[i]=n)})),e}},{key:"cfiFromRange",value:function(t){return new ft(t,this.cfiBase).toString()}},{key:"cfiFromElement",value:function(t){return new ft(t,this.cfiBase).toString()}},{key:"unload",value:function(){this.document=void 0,this.contents=void 0,this.output=void 0}},{key:"destroy",value:function(){this.unload(),this.hooks.serialize.clear(),this.hooks.content.clear(),this.hooks=void 0,this.idref=void 0,this.linear=void 0,this.properties=void 0,this.index=void 0,this.href=void 0,this.url=void 0,this.next=void 0,this.prev=void 0,this.cfiBase=void 0}}],e&&Ct(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),Lt=Pt;function _t(t){return _t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_t(t)}function Ot(t,e){for(var i=0;i0;){var i=this.get(e-1);if(i&&i.linear)return i;e-=1}}.bind(n),t.next=function(){for(var e=t.index;e-1)return delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)}},{key:"each",value:function(){return this.spineItems.forEach.apply(this.spineItems,arguments)}},{key:"first",value:function(){var t=0;do{var e=this.get(t);if(e&&e.linear)return e;t+=1}while(t=0)}},{key:"destroy",value:function(){this.each((function(t){return t.destroy()})),this.spineItems=void 0,this.spineByHref=void 0,this.spineById=void 0,this.hooks.serialize.clear(),this.hooks.content.clear(),this.hooks=void 0,this.epubcfi=void 0,this.loaded=!1,this.items=void 0,this.manifest=void 0,this.spineNodeIndex=void 0,this.baseUrl=void 0,this.length=void 0}}],e&&Ot(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),Rt=zt;function Nt(t){return Nt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Nt(t)}function Bt(t,e){for(var i=0;io&&(a+=o,l=o);l=o)a+=o-l,l=o;else{l+=i,n.endContainer=t,n.endOffset=l;var u=new ft(n,e).toString();r.push(u),a=0}s=t}.bind(this)),n&&n.startContainer&&s){n.endContainer=s,n.endOffset=s.length;var l=new ft(n,e).toString();r.push(l),a=0}return r}},{key:"generateFromWords",value:function(t,e,i){var n=t?new ft(t):void 0;return this.q.pause(),this._locationsWords=[],this._wordCounter=0,this.spine.each(function(t){t.linear&&(n?t.index>=n.spinePos&&this.q.enqueue(this.processWords.bind(this),t,e,n,i):this.q.enqueue(this.processWords.bind(this),t,e,n,i))}.bind(this)),this.q.run().then(function(){return this._currentCfi&&(this.currentLocation=this._currentCfi),this._locationsWords}.bind(this))}},{key:"processWords",value:function(t,e,i,n){return n&&this._locationsWords.length>=n?Promise.resolve():t.load(this.request).then(function(s){var r=new X,o=this.parseWords(s,t,e,i),a=n-this._locationsWords.length;return this._locationsWords=this._locationsWords.concat(o.length>=n?o.slice(0,a):o),t.unload(),this.processingTimeout=setTimeout((function(){return r.resolve(o)}),this.pause),r.promise}.bind(this))}},{key:"countWords",value:function(t){return(t=(t=(t=t.replace(/(^\s*)|(\s*$)/gi,"")).replace(/[ ]{2,}/gi," ")).replace(/\n /,"\n")).split(" ").length}},{key:"parseWords",value:function(t,e,i,n){var s,r=e.cfiBase,o=[],a=M(t.ownerDocument,"body"),h=i,l=!n||n.spinePos!==e.index;return n&&e.index===n.spinePos&&(s=n.findNode(n.range?n.path.steps.concat(n.start.steps):n.path.steps,t.ownerDocument)),U(a,function(t){if(!l){if(t!==s)return!1;l=!0}if(t.textContent.length<10&&0===t.textContent.trim().length)return!1;var e,i=this.countWords(t.textContent),n=0;if(0===i)return!1;for((e=h-this._wordCounter)>i&&(this._wordCounter+=i,n=i);n=i)this._wordCounter+=i-n,n=i;else{n+=e;var a=new ft(t,r);o.push({cfi:a.toString(),wordCount:this._wordCounter}),this._wordCounter=0}}.bind(this)),o}},{key:"locationFromCfi",value:function(t){var e;return ft.prototype.isCfiString(t)&&(t=new ft(t)),0===this._locations.length?-1:(e=S(t,this._locations,this.epubcfi.compare))>this.total?this.total:e}},{key:"percentageFromCfi",value:function(t){if(0===this._locations.length)return null;var e=this.locationFromCfi(t);return this.percentageFromLocation(e)}},{key:"percentageFromLocation",value:function(t){return t&&this.total?t/this.total:0}},{key:"cfiFromLocation",value:function(t){var e=-1;return"number"!=typeof t&&(t=parseInt(t)),t>=0&&t1&&console.warn("Normalize cfiFromPercentage value to between 0 - 1"),t>=1){var i=new ft(this._locations[this.total]);return i.collapse(),i.toString()}return e=Math.ceil(this.total*t),this.cfiFromLocation(e)}},{key:"load",value:function(t){return this._locations="string"==typeof t?JSON.parse(t):t,this.total=this._locations.length-1,this._locations}},{key:"save",value:function(){return JSON.stringify(this._locations)}},{key:"getCurrent",value:function(){return this._current}},{key:"setCurrent",value:function(t){var e;if("string"==typeof t)this._currentCfi=t;else{if("number"!=typeof t)return;this._current=t}0!==this._locations.length&&("string"==typeof t?(e=this.locationFromCfi(t),this._current=e):e=t,this.emit(Yt,{percentage:this.percentageFromLocation(e)}))}},{key:"currentLocation",get:function(){return this._current},set:function(t){this.setCurrent(t)}},{key:"length",value:function(){return this._locations.length}},{key:"destroy",value:function(){this.spine=void 0,this.request=void 0,this.pause=void 0,this.q.stop(),this.q=void 0,this.epubcfi=void 0,this._locations=void 0,this.total=void 0,this.break=void 0,this._current=void 0,this.currentLocation=void 0,this._currentCfi=void 0,clearTimeout(this.processingTimeout)}}],e&&Pe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();r()(_e.prototype);var Oe=_e;function je(t){return je="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},je(t)}function ze(t,e){for(var i=0;i0?i.childNodes[0].nodeValue.trim():""}},{key:"findNavPath",value:function(t){var e=F(t,"item",{properties:"nav"});return!!e&&e.getAttribute("href")}},{key:"findNcxPath",value:function(t,e){var i,n=F(t,"item",{"media-type":"application/x-dtbncx+xml"});return n||(i=e.getAttribute("toc"))&&(n=t.querySelector("#".concat(i))),!!n&&n.getAttribute("href")}},{key:"findCoverPath",value:function(t){M(t,"package").getAttribute("version");var e=F(t,"item",{properties:"cover-image"});if(e)return e.getAttribute("href");var i=F(t,"meta",{name:"cover"});if(i){var n=i.getAttribute("content"),s=t.getElementById(n);return s?s.getAttribute("href"):""}return!1}},{key:"getElementText",value:function(t,e){var i,n=t.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",e);return n&&0!==n.length&&(i=n[0]).childNodes.length?i.childNodes[0].nodeValue:""}},{key:"getPropertyText",value:function(t,e){var i=F(t,"meta",{property:e});return i&&i.childNodes.length?i.childNodes[0].nodeValue:""}},{key:"load",value:function(t){var e=this;this.metadata=t.metadata;var i=t.readingOrder||t.spine;return this.spine=i.map((function(t,e){return t.index=e,t.linear=t.linear||"yes",t})),t.resources.forEach((function(t,i){e.manifest[i]=t,t.rel&&"cover"===t.rel[0]&&(e.coverPath=t.href)})),this.spineNodeIndex=0,this.toc=t.toc.map((function(t,e){return t.label=t.title,t})),{metadata:this.metadata,spine:this.spine,manifest:this.manifest,navPath:this.navPath,ncxPath:this.ncxPath,coverPath:this.coverPath,spineNodeIndex:this.spineNodeIndex,toc:this.toc}}},{key:"destroy",value:function(){this.manifest=void 0,this.navPath=void 0,this.ncxPath=void 0,this.coverPath=void 0,this.spineNodeIndex=void 0,this.spine=void 0,this.metadata=void 0}}],e&&qe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),Me=Ae;function We(t){return We="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},We(t)}function Fe(t,e){for(var i=0;i-1&&(this.replacementUrls[e]=t)}.bind(this));i.push(s)}.bind(this)),Promise.all(i)}},{key:"createCssFile",value:function(t){var e=this;if(tt().isAbsolute(t))return new Promise((function(t){t()}));var i,n=this.settings.resolver(t);i=this.settings.archive?this.settings.archive.getText(n):this.settings.request(n,"text");var s=this.urls.map((function(t){var i=e.settings.resolver(t);return new st(n).relative(i)}));return i?i.then((function(t){return t=xt(t,s,e.replacementUrls),"base64"===e.settings.replacements?q(t,"text/css"):N(t,"text/css")}),(function(t){return new Promise((function(t){t()}))})):new Promise((function(t){t()}))}},{key:"relativeTo",value:function(t,e){return e=e||this.settings.resolver,this.urls.map(function(i){var n=e(i);return new st(t).relative(n)}.bind(this))}},{key:"get",value:function(t){var e=this.urls.indexOf(t);if(-1!==e)return this.replacementUrls.length?new Promise(function(t,i){t(this.replacementUrls[e])}.bind(this)):this.createUrl(t)}},{key:"substitute",value:function(t,e){return xt(t,e?this.relativeTo(e):this.urls,this.replacementUrls)}},{key:"destroy",value:function(){this.settings=void 0,this.manifest=void 0,this.resources=void 0,this.replacementUrls=void 0,this.html=void 0,this.assets=void 0,this.css=void 0,this.urls=void 0,this.cssUrls=void 0}}],e&&Qe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),Ge=$e;function Ke(t){return Ke="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ke(t)}function ti(t,e){for(var i=0;i1&&e[1],href:s,packageUrl:i,page:o}):{href:s,page:o}}},{key:"process",value:function(t){t.forEach((function(t){this.pages.push(t.page),t.cfi&&this.locations.push(t.cfi)}),this),this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage}},{key:"pageFromCfi",value:function(t){var e=-1;if(0===this.locations.length)return-1;var i=T(t,this.locations,this.epubcfi.compare);return-1!=i?e=this.pages[i]:void 0!==(e=(i=S(t,this.locations,this.epubcfi.compare))-1>=0?this.pages[i-1]:this.pages[0])||(e=-1),e}},{key:"cfiFromPage",value:function(t){var e=-1;"number"!=typeof t&&(t=parseInt(t));var i=this.pages.indexOf(t);return-1!=i&&(e=this.locations[i]),e}},{key:"pageFromPercentage",value:function(t){return Math.round(this.totalPages*t)}},{key:"percentageFromPage",value:function(t){var e=(t-this.firstPage)/this.totalPages;return Math.round(1e3*e)/1e3}},{key:"percentageFromCfi",value:function(t){var e=this.pageFromCfi(t);return this.percentageFromPage(e)}},{key:"destroy",value:function(){this.pages=void 0,this.locations=void 0,this.epubcfi=void 0,this.pageList=void 0,this.toc=void 0,this.ncx=void 0}}])&&ti(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function ni(t){return ni="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ni(t)}function si(t,e){for(var i=0;i=0&&(this._minSpreadWidth=e),this._spread}},{key:"calculate",value:function(t,e,i){var n,s,r,o,a,h=i||0,l=t,u=e,c=Math.floor(l/12);a=this._spread&&l>=this._minSpreadWidth?2:1,"reflowable"!==this.name||"paginated"!==this._flow||i>=0||(h=c%2==0?c:c-1),"pre-paginated"===this.name&&(h=0),a>1?r=(n=l/a-h)+h:(n=l,r=l),"pre-paginated"===this.name&&a>1&&(l=n),s=n*a+h,o=l,this.width=l,this.height=u,this.spreadWidth=s,this.pageWidth=r,this.delta=o,this.columnWidth=n,this.gap=h,this.divisor=a,this.update({width:l,height:u,spreadWidth:s,pageWidth:r,delta:o,columnWidth:n,gap:h,divisor:a})}},{key:"format",value:function(t,e,i){return"pre-paginated"===this.name?t.fit(this.columnWidth,this.height,e):"paginated"===this._flow?t.columns(this.width,this.height,this.columnWidth,this.gap,this.settings.direction):i&&"horizontal"===i?t.size(null,this.height):t.size(this.width,null)}},{key:"count",value:function(t,e){var i,n;return"pre-paginated"===this.name?(i=1,n=1):"paginated"===this._flow?(e=e||this.delta,n=(i=Math.ceil(t/e))*this.divisor):(e=e||this.height,n=i=Math.ceil(t/e)),{spreads:i,pages:n}}},{key:"update",value:function(t){var e=this;if(Object.keys(t).forEach((function(i){e.props[i]===t[i]&&delete t[i]})),Object.keys(t).length>0){var i=k(this.props,t);this.emit(Se,i,t)}}}],e&&si(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();r()(oi.prototype);var ai=oi;function hi(t){return hi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},hi(t)}function li(t,e){for(var i=0;i0||e.url&&-1===i.indexOf(e.url))&&this.add(s,t),this._injected.push(s));"default"!=this._current&&t.addClass(this._current)}},{key:"add",value:function(t,e){var i=this._themes[t];i&&e&&(i.url?e.addStylesheet(i.url):i.serialized?(e.addStylesheetCss(i.serialized,t),i.injected=!0):i.rules&&(e.addStylesheetRules(i.rules,t),i.injected=!0))}},{key:"override",value:function(t,e,i){var n=this,s=this.rendition.getContents();this._overrides[t]={value:e,priority:!0===i},s.forEach((function(e){e.css(t,n._overrides[t].value,n._overrides[t].priority)}))}},{key:"removeOverride",value:function(t){var e=this.rendition.getContents();delete this._overrides[t],e.forEach((function(e){e.css(t)}))}},{key:"overrides",value:function(t){var e=this._overrides;for(var i in e)e.hasOwnProperty(i)&&t.css(i,e[i].value,e[i].priority)}},{key:"fontSize",value:function(t){this.override("font-size",t)}},{key:"font",value:function(t){this.override("font-family",t,!0)}},{key:"destroy",value:function(){this.rendition=void 0,this._themes=void 0,this._overrides=void 0,this._current=void 0,this._injected=void 0}}],e&&li(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),di=ci;function fi(t){return fi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fi(t)}function pi(t,e){for(var i=0;i3&&void 0!==arguments[3]&&arguments[3];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.layout=e,this.horizontal="horizontal"===n,this.direction=i||"ltr",this._dev=s},e=[{key:"section",value:function(t){var e=this.findRanges(t);return this.rangeListToCfiList(t.section.cfiBase,e)}},{key:"page",value:function(t,e,i,n){var s,r=!(!t||!t.document)&&t.document.body;if(r){if(s=this.rangePairToCfiPair(e,{start:this.findStart(r,i,n),end:this.findEnd(r,i,n)}),!0===this._dev){var o=t.document,a=new ft(s.start).toRange(o),h=new ft(s.end).toRange(o),l=o.defaultView.getSelection(),u=o.createRange();l.removeAllRanges(),u.setStart(a.startContainer,a.startOffset),u.setEnd(h.endContainer,h.endOffset),l.addRange(u)}return s}}},{key:"walk",value:function(t,e){if(!t||t.nodeType!==Node.TEXT_NODE){var i=function(t){return t.data.trim().length>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT},n=i;n.acceptNode=i;for(var s,r,o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,n,!1);(s=o.nextNode())&&!(r=e(s)););return r}}},{key:"findRanges",value:function(t){for(var e,i,n=[],s=t.contents.scrollWidth(),r=Math.ceil(s/this.layout.spreadWidth)*this.layout.divisor,o=this.layout.columnWidth,a=this.layout.gap,h=0;h=e&&n<=i)return t;if(s>e)return t;a=t,o.push(t)}else if(r.horizontal&&"rtl"===r.direction){if(n=u.left,(s=u.right)<=i&&s>=e)return t;if(n=e&&h<=i)return t;if(l>e)return t;a=t,o.push(t)}})))return this.findTextStartRange(s,e,i);return this.findTextStartRange(a,e,i)}},{key:"findEnd",value:function(t,e,i){for(var n,s,r=this,o=[t],a=t;o.length;)if(n=o.shift(),s=this.walk(n,(function(t){var n,s,h,l,u;if(u=P(t),r.horizontal&&"ltr"===r.direction){if(n=Math.round(u.left),s=Math.round(u.right),n>i&&a)return a;if(s>i)return t;a=t,o.push(t)}else if(r.horizontal&&"rtl"===r.direction){if(n=Math.round(r.horizontal?u.left:u.top),(s=Math.round(r.horizontal?u.right:u.bottom))i&&a)return a;if(l>i)return t;a=t,o.push(t)}})))return this.findTextEndRange(s,e,i);return this.findTextEndRange(a,e,i)}},{key:"findTextStartRange",value:function(t,e,i){for(var n,s,r=this.splitTextNodeIntoRanges(t),o=0;o=e)return n}else if(this.horizontal&&"rtl"===this.direction){if(s.right<=i)return n}else if(s.top>=e)return n;return r[0]}},{key:"findTextEndRange",value:function(t,e,i){for(var n,s,r,o,a,h,l,u=this.splitTextNodeIntoRanges(t),c=0;ci&&n)return n;if(a>i)return s}else if(this.horizontal&&"rtl"===this.direction){if(o=r.left,(a=r.right)i&&n)return n;if(l>i)return s}n=s}return u[u.length-1]}},{key:"splitTextNodeIntoRanges",value:function(t,e){var i,n=[],s=(t.textContent||"").trim(),r=t.ownerDocument,o=e||" ",a=s.indexOf(o);if(-1===a||t.nodeType!=Node.TEXT_NODE)return(i=r.createRange()).selectNodeContents(t),[i];for((i=r.createRange()).setStart(t,0),i.setEnd(t,a),n.push(i),i=!1;-1!=a;)(a=s.indexOf(o,a+1))>0&&(i&&(i.setEnd(t,a),n.push(i)),(i=r.createRange()).setStart(t,a+1));return i&&(i.setEnd(t,s.length),n.push(i)),n}},{key:"rangePairToCfiPair",value:function(t,e){var i=e.start,n=e.end;return i.collapse(!0),n.collapse(!1),{start:new ft(i,t).toString(),end:new ft(n,t).toString()}}},{key:"rangeListToCfiList",value:function(t,e){for(var i,n=[],s=0;s0?(a.setStart(o,s.startOffset-2),a.setEnd(o,s.startOffset),i=a.getBoundingClientRect()):i=o.parentNode.getBoundingClientRect()}catch(t){console.error(t,t.stack)}}else i=s.getBoundingClientRect()}}else if("string"==typeof t&&t.indexOf("#")>-1){var h=t.substring(t.indexOf("#")+1),l=this.document.getElementById(h);if(l)if(Si){var u=new Range;u.selectNode(l),i=u.getBoundingClientRect()}else i=l.getBoundingClientRect()}return i&&(n.left=i.left,n.top=i.top),n}},{key:"addStylesheet",value:function(t){return new Promise(function(e,i){var n,s=!1;this.document?(n=this.document.querySelector("link[href='"+t+"']"))?e(!0):((n=this.document.createElement("link")).type="text/css",n.rel="stylesheet",n.href=t,n.onload=n.onreadystatechange=function(){s||this.readyState&&"complete"!=this.readyState||(s=!0,setTimeout((function(){e(!0)}),1))},this.document.head.appendChild(n)):e(!1)}.bind(this))}},{key:"_getStylesheetNode",value:function(t){var e;return t="epubjs-inserted-css-"+(t||""),!!this.document&&((e=this.document.getElementById(t))||((e=this.document.createElement("style")).id=t,this.document.head.appendChild(e)),e)}},{key:"addStylesheetCss",value:function(t,e){return!(!this.document||!t||(this._getStylesheetNode(e).innerHTML=t,0))}},{key:"addStylesheetRules",value:function(t,e){var i;if(this.document&&t&&0!==t.length)if(i=this._getStylesheetNode(e).sheet,"[object Array]"===Object.prototype.toString.call(t))for(var n=0,s=t.length;n0&&((e=t.getRangeAt(0)).collapsed||(i=new ft(e,this.cfiBase).toString(),this.emit(Ht,i),this.emit(Vt,e)))}},{key:"range",value:function(t,e){return new ft(t).toRange(this.document,e)}},{key:"cfiFromRange",value:function(t,e){return new ft(t,this.cfiBase,e).toString()}},{key:"cfiFromNode",value:function(t,e){return new ft(t,this.cfiBase,e).toString()}},{key:"map",value:function(t){return new mi(t).section()}},{key:"size",value:function(t,e){var i={scale:1,scalable:"no"};this.layoutStyle("scrolling"),t>=0&&(this.width(t),i.width=t,this.css("padding","0 "+t/12+"px")),e>=0&&(this.height(e),i.height=e),this.css("margin","0"),this.css("box-sizing","border-box"),this.viewport(i)}},{key:"columns",value:function(t,e,i,n,s){var r=b("column-axis"),o=b("column-gap"),a=b("column-width"),h=b("column-fill"),l=0===this.writingMode().indexOf("vertical")?"vertical":"horizontal";this.layoutStyle("paginated"),"rtl"===s&&"horizontal"===l&&this.direction(s),this.width(t),this.height(e),this.viewport({width:t,height:e,scale:1,scalable:"no"}),this.css("overflow-y","hidden"),this.css("margin","0",!0),"vertical"===l?(this.css("padding-top",n/2+"px",!0),this.css("padding-bottom",n/2+"px",!0),this.css("padding-left","20px"),this.css("padding-right","20px"),this.css(r,"vertical")):(this.css("padding-top","20px"),this.css("padding-bottom","20px"),this.css("padding-left",n/2+"px",!0),this.css("padding-right",n/2+"px",!0),this.css(r,"horizontal")),this.css("box-sizing","border-box"),this.css("max-width","inherit"),this.css(h,"auto"),this.css(o,n+"px"),this.css(a,i+"px"),this.css("-webkit-line-box-contain","block glyphs replaced")}},{key:"scaler",value:function(t,e,i){var n="scale("+t+")",s="";this.css("transform-origin","top left"),(e>=0||i>=0)&&(s=" translate("+(e||0)+"px, "+(i||0)+"px )"),this.css("transform",n+s)}},{key:"fit",value:function(t,e,i){var n=this.viewport(),s=parseInt(n.width),r=parseInt(n.height),o=t/s,a=e/r,h=o-1)t.setAttribute("target","_blank");else{var n;try{n=new ht(i,s)}catch(t){}t.onclick=function(){return n&&n.hash?e(n.Path.path+n.hash):e(n?n.Path.path:i),!1}}}.bind(this),o=0;o0&&(i=Math.ceil(i/this.layout.pageWidth)*this.layout.pageWidth),this.settings.forceEvenPages&&(e=i/this.layout.pageWidth,this.layout.divisor>1&&"reflowable"===this.layout.name&&e%2>0&&(i+=this.layout.pageWidth))):"vertical"===this.settings.axis&&(n=this.contents.textHeight(),"paginated"===this.settings.flow&&n%this.layout.height>0&&(n=Math.ceil(n/this.layout.height)*this.layout.height)),(this._needsReframe||i!=this._width||n!=this._height)&&this.reframe(i,n),this._expanding=!1)}},{key:"reframe",value:function(t,e){var i,n=this;m(t)&&(this.element.style.width=t+"px",this.iframe.style.width=t+"px",this._width=t),m(e)&&(this.element.style.height=e+"px",this.iframe.style.height=e+"px",this._height=e),i={width:t,height:e,widthDelta:this.prevBounds?t-this.prevBounds.width:t,heightDelta:this.prevBounds?e-this.prevBounds.height:e},this.pane&&this.pane.render(),requestAnimationFrame((function(){var t;for(var e in n.marks)n.marks.hasOwnProperty(e)&&(t=n.marks[e],n.placeMark(t.element,t.range))})),this.onResize(this,i),this.emit(re,i),this.prevBounds=i,this.elementBounds=C(this.element)}},{key:"load",value:function(t){var e=new X,i=e.promise;if(!this.iframe)return e.reject(new Error("No Iframe Available")),i;if(this.iframe.onload=function(t){this.onLoad(t,e)}.bind(this),"blobUrl"===this.settings.method)this.blobUrl=N(t,"application/xhtml+xml"),this.iframe.src=this.blobUrl,this.element.appendChild(this.iframe);else if("srcdoc"===this.settings.method)this.iframe.srcdoc=t,this.element.appendChild(this.iframe);else{if(this.element.appendChild(this.iframe),this.document=this.iframe.contentDocument,!this.document)return e.reject(new Error("No Document Available")),i;if(this.iframe.contentDocument.open(),window.MSApp&&MSApp.execUnsafeLocalFunction){var n=this;MSApp.execUnsafeLocalFunction((function(){n.iframe.contentDocument.write(t)}))}else this.iframe.contentDocument.write(t);this.iframe.contentDocument.close()}return i}},{key:"onLoad",value:function(t,e){var i=this;this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,this.contents=new Ci(this.document,this.document.body,this.section.cfiBase,this.section.index),this.rendering=!1;var n=this.document.querySelector("link[rel='canonical']");n?n.setAttribute("href",this.section.canonical):((n=this.document.createElement("link")).setAttribute("rel","canonical"),n.setAttribute("href",this.section.canonical),this.document.querySelector("head").appendChild(n)),this.contents.on(Ut,(function(){i.displayed&&i.iframe&&(i.expand(),i.contents&&i.layout.format(i.contents))})),this.contents.on(Dt,(function(t){i.displayed&&i.iframe&&(i.expand(),i.contents&&i.layout.format(i.contents))})),e.resolve(this.contents)}},{key:"setLayout",value:function(t){this.layout=t,this.contents&&(this.layout.format(this.contents),this.expand())}},{key:"setAxis",value:function(t){this.settings.axis=t,this.element.style.flex="horizontal"==t?"none":"initial",this.size()}},{key:"setWritingMode",value:function(t){this.writingMode=t}},{key:"addListeners",value:function(){}},{key:"removeListeners",value:function(t){}},{key:"display",value:function(t){var e=new X;return this.displayed?e.resolve(this):this.render(t).then(function(){this.emit(oe,this),this.onDisplayed(this),this.displayed=!0,e.resolve(this)}.bind(this),(function(t){e.reject(t,this)})),e.promise}},{key:"show",value:function(){this.element.style.visibility="visible",this.iframe&&(this.iframe.style.visibility="visible",this.iframe.style.transform="translateZ(0)",this.iframe.offsetWidth,this.iframe.style.transform=null),this.emit(ae,this)}},{key:"hide",value:function(){this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.stopExpanding=!0,this.emit(he,this)}},{key:"offset",value:function(){return{top:this.element.offsetTop,left:this.element.offsetLeft}}},{key:"width",value:function(){return this._width}},{key:"height",value:function(){return this._height}},{key:"position",value:function(){return this.element.getBoundingClientRect()}},{key:"locationOf",value:function(t){this.iframe.getBoundingClientRect();var e=this.contents.locationOf(t,this.settings.ignoreClass);return{left:e.left,top:e.top}}},{key:"onDisplayed",value:function(t){}},{key:"onResize",value:function(t,e){}},{key:"bounds",value:function(t){return!t&&this.elementBounds||(this.elementBounds=C(this.element)),this.elementBounds}},{key:"highlight",value:function(t){var e=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"epubjs-hl",r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(this.contents){var o=Object.assign({fill:"yellow","fill-opacity":"0.3","mix-blend-mode":"multiply"},r),a=this.contents.range(t),h=function(){e.emit(le,t,i)};i.epubcfi=t,this.pane||(this.pane=new Ni.Zv(this.iframe,this.element));var l=new Ni.f4(a,s,i,o),u=this.pane.addMark(l);return this.highlights[t]={mark:u,element:u.element,listeners:[h,n]},u.element.setAttribute("ref",s),u.element.addEventListener("click",h),u.element.addEventListener("touchstart",h),n&&(u.element.addEventListener("click",n),u.element.addEventListener("touchstart",n)),u}}},{key:"underline",value:function(t){var e=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"epubjs-ul",r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(this.contents){var o=Object.assign({stroke:"black","stroke-opacity":"0.3","mix-blend-mode":"multiply"},r),a=this.contents.range(t),h=function(){e.emit(le,t,i)};i.epubcfi=t,this.pane||(this.pane=new Ni.Zv(this.iframe,this.element));var l=new Ni.z2(a,s,i,o),u=this.pane.addMark(l);return this.underlines[t]={mark:u,element:u.element,listeners:[h,n]},u.element.setAttribute("ref",s),u.element.addEventListener("click",h),u.element.addEventListener("touchstart",h),n&&(u.element.addEventListener("click",n),u.element.addEventListener("touchstart",n)),u}}},{key:"mark",value:function(t){var e=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;if(this.contents){if(t in this.marks)return this.marks[t];var s=this.contents.range(t);if(s){var r=s.commonAncestorContainer,o=1===r.nodeType?r:r.parentNode,a=function(n){e.emit(le,t,i)};s.collapsed&&1===r.nodeType?(s=new Range).selectNodeContents(r):s.collapsed&&(s=new Range).selectNodeContents(o);var h=this.document.createElement("a");return h.setAttribute("ref","epubjs-mk"),h.style.position="absolute",h.dataset.epubcfi=t,i&&Object.keys(i).forEach((function(t){h.dataset[t]=i[t]})),n&&(h.addEventListener("click",n),h.addEventListener("touchstart",n)),h.addEventListener("click",a),h.addEventListener("touchstart",a),this.placeMark(h,s),this.element.appendChild(h),this.marks[t]={element:h,range:s,listeners:[a,n]},o}}}},{key:"placeMark",value:function(t,e){var i,n,s;if("pre-paginated"===this.layout.name||"horizontal"!==this.settings.axis){var r=e.getBoundingClientRect();i=r.top,n=r.right}else for(var o,a=e.getClientRects(),h=0;h!=a.length;h++)o=a[h],(!s||o.left-1&&this._views.splice(e,1),this.destroy(t),this.length--}},{key:"destroy",value:function(t){t.displayed&&t.destroy(),this.container&&this.container.removeChild(t.element),t=null}},{key:"forEach",value:function(){return this._views.forEach.apply(this._views,arguments)}},{key:"clear",value:function(){var t,e=this.length;if(this.length){for(var i=0;i0?t="default":"undefined"!=typeof Element&&Element.prototype.scrollIntoView?(e.children[0].children[1].scrollIntoView(),e.scrollLeft<0&&(t="negative")):(e.scrollLeft=1,0===e.scrollLeft&&(t="negative")),document.body.removeChild(e),t}(),this.stage=new Xi({width:e.width,height:e.height,overflow:this.overflow,hidden:this.settings.hidden,axis:this.settings.axis,fullsize:this.settings.fullsize,direction:this.settings.direction}),this.stage.attachTo(t),this.container=this.stage.getContainer(),this.views=new $i(this.container),this._bounds=this.bounds(),this._stageSize=this.stage.size(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.stage.onResize(this.onResized.bind(this)),this.stage.onOrientationChange(this.onOrientationChange.bind(this)),this.addEventListeners(),this.layout&&this.updateLayout(),this.rendered=!0}},{key:"addEventListeners",value:function(){var t;window.addEventListener("unload",function(t){this.destroy()}.bind(this)),t=this.settings.fullsize?window:this.container,this._onScroll=this.onScroll.bind(this),t.addEventListener("scroll",this._onScroll)}},{key:"removeEventListeners",value:function(){(this.settings.fullsize?window:this.container).removeEventListener("scroll",this._onScroll),this._onScroll=void 0}},{key:"destroy",value:function(){clearTimeout(this.orientationTimeout),clearTimeout(this.resizeTimeout),clearTimeout(this.afterScrolled),this.clear(),this.removeEventListeners(),this.stage.destroy(),this.rendered=!1}},{key:"onOrientationChange",value:function(t){var e=window.orientation;this.optsSettings.resizeOnOrientationChange&&this.resize(),clearTimeout(this.orientationTimeout),this.orientationTimeout=setTimeout(function(){this.orientationTimeout=void 0,this.optsSettings.resizeOnOrientationChange&&this.resize(),this.emit(Zt,e)}.bind(this),500)}},{key:"onResized",value:function(t){this.resize()}},{key:"resize",value:function(t,e,i){var n=this.stage.size(t,e);this.winBounds=L(),this.orientationTimeout&&this.winBounds.width===this.winBounds.height?this._stageSize=void 0:this._stageSize&&this._stageSize.width===n.width&&this._stageSize.height===n.height||(this._stageSize=n,this._bounds=this.bounds(),this.clear(),this.viewSettings.width=this._stageSize.width,this.viewSettings.height=this._stageSize.height,this.updateLayout(),this.emit(Qt,{width:this._stageSize.width,height:this._stageSize.height},i))}},{key:"createView",value:function(t,e){return new this.View(t,k(this.viewSettings,{forceRight:e}))}},{key:"handleNextPrePaginated",value:function(t,e,i){var n;if("pre-paginated"===this.layout.name&&this.layout.divisor>1){if(t||0===e.index)return;if((n=e.next())&&!n.properties.includes("page-spread-left"))return i.call(this,n)}}},{key:"display",value:function(t,e){var i=new X,n=i.promise;(e===t.href||m(e))&&(e=void 0);var s=this.views.find(t);if(s&&t&&"pre-paginated"!==this.layout.name){var r=s.offset();if("ltr"===this.settings.direction)this.scrollTo(r.left,r.top,!0);else{var o=s.width();this.scrollTo(r.left+o,r.top,!0)}if(e){var a=s.locationOf(e),h=s.width();this.moveTo(a,h)}return i.resolve(),n}this.clear();var l=!1;return"pre-paginated"===this.layout.name&&2===this.layout.divisor&&t.properties.includes("page-spread-right")&&(l=!0),this.add(t,l).then(function(t){if(e){var i=t.locationOf(e),n=t.width();this.moveTo(i,n)}}.bind(this),(function(t){i.reject(t)})).then(function(){return this.handleNextPrePaginated(l,t,this.add)}.bind(this)).then(function(){this.views.show(),i.resolve()}.bind(this)),n}},{key:"afterDisplayed",value:function(t){this.emit($t,t)}},{key:"afterResized",value:function(t){this.emit(Jt,t.section)}},{key:"moveTo",value:function(t,e){var i=0,n=0;this.isPaginated?((i=Math.floor(t.left/this.layout.delta)*this.layout.delta)+this.layout.delta>this.container.scrollWidth&&(i=this.container.scrollWidth-this.layout.delta),(n=Math.floor(t.top/this.layout.delta)*this.layout.delta)+this.layout.delta>this.container.scrollHeight&&(n=this.container.scrollHeight-this.layout.delta)):n=t.top,"rtl"===this.settings.direction&&(i+=this.layout.delta,i-=e),this.scrollTo(i,n,!0)}},{key:"add",value:function(t,e){var i=this,n=this.createView(t,e);return this.views.append(n),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.on(ee,(function(t){i.updateAxis(t)})),n.on(ie,(function(t){i.updateWritingMode(t)})),n.display(this.request)}},{key:"append",value:function(t,e){var i=this,n=this.createView(t,e);return this.views.append(n),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.on(ee,(function(t){i.updateAxis(t)})),n.on(ie,(function(t){i.updateWritingMode(t)})),n.display(this.request)}},{key:"prepend",value:function(t,e){var i=this,n=this.createView(t,e);return n.on(re,(function(t){i.counter(t)})),this.views.prepend(n),n.onDisplayed=this.afterDisplayed.bind(this),n.onResize=this.afterResized.bind(this),n.on(ee,(function(t){i.updateAxis(t)})),n.on(ie,(function(t){i.updateWritingMode(t)})),n.display(this.request)}},{key:"counter",value:function(t){"vertical"===this.settings.axis?this.scrollBy(0,t.heightDelta,!0):this.scrollBy(t.widthDelta,0,!0)}},{key:"next",value:function(){var t,e=this.settings.direction;if(this.views.length&&(!this.isPaginated||"horizontal"!==this.settings.axis||e&&"ltr"!==e?this.isPaginated&&"horizontal"===this.settings.axis&&"rtl"===e?(this.scrollLeft=this.container.scrollLeft,"default"===this.settings.rtlScrollType?this.container.scrollLeft>0?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next():this.container.scrollLeft+-1*this.layout.delta>-1*this.container.scrollWidth?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next()):this.isPaginated&&"vertical"===this.settings.axis?(this.scrollTop=this.container.scrollTop,this.container.scrollTop+this.container.offsetHeight0?this.scrollBy(0,-this.layout.height,!0):t=this.views.first().section.prev()):t=this.views.first().section.prev():(this.scrollLeft=this.container.scrollLeft,this.container.scrollLeft>0?this.scrollBy(-this.layout.delta,0,!0):t=this.views.first().section.prev()),t)){this.clear(),this.updateLayout();var i=!1;return"pre-paginated"===this.layout.name&&2===this.layout.divisor&&"object"!==Gi(t.prev())&&(i=!0),this.prepend(t,i).then(function(){var e;if("pre-paginated"===this.layout.name&&this.layout.divisor>1&&(e=t.prev()))return this.prepend(e)}.bind(this),(function(t){return t})).then(function(){this.isPaginated&&"horizontal"===this.settings.axis&&("rtl"===this.settings.direction?"default"===this.settings.rtlScrollType?this.scrollTo(0,0,!0):this.scrollTo(-1*this.container.scrollWidth+this.layout.delta,0,!0):this.scrollTo(this.container.scrollWidth-this.layout.delta,0,!0)),this.views.show()}.bind(this))}}},{key:"current",value:function(){var t=this.visible();return t.length?t[t.length-1]:null}},{key:"clear",value:function(){this.views&&(this.views.hide(),this.scrollTo(0,0,!0),this.views.clear())}},{key:"currentLocation",value:function(){return this.updateLayout(),this.isPaginated&&"horizontal"===this.settings.axis?this.location=this.paginatedLocation():this.location=this.scrolledLocation(),this.location}},{key:"scrolledLocation",value:function(){var t=this,e=this.visible(),i=this.container.getBoundingClientRect(),n=i.heightr.left-e&&s.leftr.top-e&&s.top0&&"pre-paginated"===this.layout.name&&this.display(this.views.first().section)}},{key:"updateLayout",value:function(){this.stage&&(this._stageSize=this.stage.size(),this.isPaginated?(this.layout.calculate(this._stageSize.width,this._stageSize.height,this.settings.gap),this.settings.offset=this.layout.delta/this.layout.divisor):this.layout.calculate(this._stageSize.width,this._stageSize.height),this.viewSettings.width=this.layout.width,this.viewSettings.height=this.layout.height,this.setLayout(this.layout))}},{key:"setLayout",value:function(t){this.viewSettings.layout=t,this.mapping=new mi(t.props,this.settings.direction,this.settings.axis),this.views&&this.views.forEach((function(e){e&&e.setLayout(t)}))}},{key:"updateWritingMode",value:function(t){this.writingMode=t}},{key:"updateAxis",value:function(t,e){(e||t!==this.settings.axis)&&(this.settings.axis=t,this.stage&&this.stage.axis(t),this.viewSettings.axis=t,this.mapping&&(this.mapping=new mi(this.layout.props,this.settings.direction,this.settings.axis)),this.layout&&("vertical"===t?this.layout.spread("none"):this.layout.spread(this.layout.settings.spread)))}},{key:"updateFlow",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"auto",i="paginated"===t||"auto"===t;this.isPaginated=i,"scrolled-doc"===t||"scrolled-continuous"===t||"scrolled"===t?this.updateAxis("vertical"):this.updateAxis("horizontal"),this.viewSettings.flow=t,this.settings.overflow?this.overflow=this.settings.overflow:this.overflow=i?"hidden":e,this.stage&&this.stage.overflow(this.overflow),this.updateLayout()}},{key:"getContents",value:function(){var t=[];return this.views?(this.views.forEach((function(e){var i=e&&e.contents;i&&t.push(i)})),t):t}},{key:"direction",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"ltr";this.settings.direction=t,this.stage&&this.stage.direction(t),this.viewSettings.direction=t,this.updateLayout()}},{key:"isRendered",value:function(){return this.rendered}}],e&&Ki(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();r()(en.prototype);var nn=en;function sn(t){return sn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},sn(t)}function rn(t,e){for(var i=0;i=t?0:n>s?-1:n<-s?1:void 0}},{key:"needsSnap",value:function(){return this.scrollLeft%(this.layout.pageWidth*this.layout.divisor)!=0}},{key:"snap",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=this.scrollLeft,i=this.layout.pageWidth*this.layout.divisor,n=Math.round(e/i)*i;return t&&(n+=t*i),this.smoothScrollTo(n)}},{key:"smoothScrollTo",value:function(t){var e=new X,i=this.scrollLeft,n=this.now(),s=this.settings.duration,r=this.settings.easing;return this.snapping=!0,function o(){var a=this.now(),h=Math.min(1,(a-n)/s);if(r(h),this.touchCanceler||this.resizeCanceler)return this.resizeCanceler=!1,this.snapping=!1,void e.resolve();h<1?(window.requestAnimationFrame(o.bind(this)),this.scrollTo(i+(t-i)*h,0)):(this.scrollTo(t,0),this.snapping=!1,e.resolve())}.call(this),e.promise}},{key:"scrollTo",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.fullsize?window.scroll(t,e):(this.scroller.scrollLeft=t,this.scroller.scrollTop=e)}},{key:"now",value:function(){return"now"in window.performance?performance.now():(new Date).getTime()}},{key:"destroy",value:function(){this.scroller&&(this.fullsize&&this.enableScroll(),this.removeListeners(),this.scroller=void 0)}}],e&&rn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();r()(ln.prototype);var un=ln,cn=i(46177),dn=i.n(cn);function fn(t){return fn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fn(t)}function pn(t,e){for(var i=0;i0||i>0)&&this.scrollBy(e,i,!0)}},{key:"afterResized",value:function(t){this.emit(Jt,t.section)}},{key:"removeShownListeners",value:function(t){t.onDisplayed=function(){}}},{key:"add",value:function(t){var e=this,i=this.createView(t);return this.views.append(i),i.on(re,(function(t){i.expanded=!0})),i.on(ee,(function(t){e.updateAxis(t)})),i.on(ie,(function(t){e.updateWritingMode(t)})),i.onDisplayed=this.afterDisplayed.bind(this),i.onResize=this.afterResized.bind(this),i.display(this.request)}},{key:"append",value:function(t){var e=this,i=this.createView(t);return i.on(re,(function(t){i.expanded=!0})),i.on(ee,(function(t){e.updateAxis(t)})),i.on(ie,(function(t){e.updateWritingMode(t)})),this.views.append(i),i.onDisplayed=this.afterDisplayed.bind(this),i}},{key:"prepend",value:function(t){var e=this,i=this.createView(t);return i.on(re,(function(t){e.counter(t),i.expanded=!0})),i.on(ee,(function(t){e.updateAxis(t)})),i.on(ie,(function(t){e.updateWritingMode(t)})),this.views.prepend(i),i.onDisplayed=this.afterDisplayed.bind(this),i}},{key:"counter",value:function(t){"vertical"===this.settings.axis?this.scrollBy(0,t.heightDelta,!0):this.scrollBy(t.widthDelta,0,!0)}},{key:"update",value:function(t){for(var e,i=this.bounds(),n=this.views.all(),s=n.length,r=[],o=void 0!==t?t:this.settings.offset||0,a=new X,h=[],l=0;l=u&&((v=(p=i.views.last())&&p.section.next())&&s.push(i.append(v))),g<0&&((m=(y=i.views.first())&&y.section.prev())&&s.push(i.prepend(m)));var b=s.map((function(t){return t.display(i.request)}));return s.length?Promise.all(b).then((function(){return i.check()})).then((function(){return i.update(o)}),(function(t){return t})):(this.q.enqueue(function(){this.update()}.bind(this)),n.resolve(!1),n.promise)}},{key:"trim",value:function(){for(var t=new X,e=this.views.displayed(),i=e[0],n=e[e.length-1],s=this.views.indexOf(i),r=this.views.indexOf(n),o=this.views.slice(0,s),a=this.views.slice(r+1),h=0;h0)&&(0===this.settings.height||this.settings.height),{layout:e,spread:i,orientation:n,flow:s,viewport:r,minSpreadWidth:o,direction:a}}},{key:"flow",value:function(t){var e=t;"scrolled"!==t&&"scrolled-doc"!==t&&"scrolled-continuous"!==t||(e="scrolled"),"auto"!==t&&"paginated"!==t||(e="paginated"),this.settings.flow=t,this._layout&&this._layout.flow(e),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this.manager&&this.manager.updateFlow(e),this.manager&&this.manager.isRendered()&&this.location&&(this.manager.clear(),this.display(this.location.start.cfi))}},{key:"layout",value:function(t){var e=this;return t&&(this._layout=new ai(t),this._layout.spread(t.spread,this.settings.minSpreadWidth),this._layout.on(Se,(function(t,i){e.emit(xe,t,i)}))),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this._layout}},{key:"spread",value:function(t,e){this.settings.spread=t,e&&(this.settings.minSpreadWidth=e),this._layout&&this._layout.spread(t,e),this.manager&&this.manager.isRendered()&&this.manager.updateLayout()}},{key:"direction",value:function(t){this.settings.direction=t||"ltr",this.manager&&this.manager.direction(this.settings.direction),this.manager&&this.manager.isRendered()&&this.location&&(this.manager.clear(),this.display(this.location.start.cfi))}},{key:"reportLocation",value:function(){return this.q.enqueue(function(){requestAnimationFrame(function(){var t=this.manager.currentLocation();if(t&&t.then&&"function"==typeof t.then)t.then(function(t){var e=this.located(t);e&&e.start&&e.end&&(this.location=e,this.emit(ge,{index:this.location.start.index,href:this.location.start.href,start:this.location.start.cfi,end:this.location.end.cfi,percentage:this.location.start.percentage}),this.emit(be,this.location))}.bind(this));else if(t){var e=this.located(t);if(!e||!e.start||!e.end)return;this.location=e,this.emit(ge,{index:this.location.start.index,href:this.location.start.href,start:this.location.start.cfi,end:this.location.end.cfi,percentage:this.location.start.percentage}),this.emit(be,this.location)}}.bind(this))}.bind(this))}},{key:"currentLocation",value:function(){var t=this.manager.currentLocation();if(t&&t.then&&"function"==typeof t.then)t.then(function(t){return this.located(t)}.bind(this));else if(t)return this.located(t)}},{key:"located",value:function(t){if(!t.length)return{};var e=t[0],i=t[t.length-1],n={start:{index:e.index,href:e.href,cfi:e.mapping.start,displayed:{page:e.pages[0]||1,total:e.totalPages}},end:{index:i.index,href:i.href,cfi:i.mapping.end,displayed:{page:i.pages[i.pages.length-1]||1,total:i.totalPages}}},s=this.book.locations.locationFromCfi(e.mapping.start),r=this.book.locations.locationFromCfi(i.mapping.end);null!=s&&(n.start.location=s,n.start.percentage=this.book.locations.percentageFromLocation(s)),null!=r&&(n.end.location=r,n.end.percentage=this.book.locations.percentageFromLocation(r));var o=this.book.pageList.pageFromCfi(e.mapping.start),a=this.book.pageList.pageFromCfi(i.mapping.end);return-1!=o&&(n.start.page=o),-1!=a&&(n.end.page=a),i.index===this.book.spine.last().index&&n.end.displayed.page>=n.end.displayed.total&&(n.atEnd=!0),e.index===this.book.spine.first().index&&1===n.start.displayed.page&&(n.atStart=!0),n}},{key:"destroy",value:function(){this.manager&&this.manager.destroy(),this.book=void 0}},{key:"passEvents",value:function(t){var e=this;Wt.forEach((function(i){t.on(i,(function(i){return e.triggerViewEvent(i,t)}))})),t.on(Ht,(function(i){return e.triggerSelectedEvent(i,t)}))}},{key:"triggerViewEvent",value:function(t,e){this.emit(t.type,t,e)}},{key:"triggerSelectedEvent",value:function(t,e){this.emit(ke,t,e)}},{key:"triggerMarkEvent",value:function(t,e,i){this.emit(we,t,e,i)}},{key:"getRange",value:function(t,e){var i=new ft(t),n=this.manager.visible().filter((function(t){if(i.spinePos===t.index)return!0}));if(n.length)return n[0].contents.range(i,e)}},{key:"adjustImages",value:function(t){if("pre-paginated"===this._layout.name)return new Promise((function(t){t()}));var e=t.window.getComputedStyle(t.content,null),i=.95*(t.content.offsetHeight-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom))),n=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight);return t.addStylesheetRules({img:{"max-width":(this._layout.columnWidth?this._layout.columnWidth-n+"px":"100%")+"!important","max-height":i+"px!important","object-fit":"contain","page-break-inside":"avoid","break-inside":"avoid","box-sizing":"border-box"},svg:{"max-width":(this._layout.columnWidth?this._layout.columnWidth-n+"px":"100%")+"!important","max-height":i+"px!important","page-break-inside":"avoid","break-inside":"avoid"}}),new Promise((function(t,e){setTimeout((function(){t()}),1)}))}},{key:"getContents",value:function(){return this.manager?this.manager.getContents():[]}},{key:"views",value:function(){return(this.manager?this.manager.views:void 0)||[]}},{key:"handleLinks",value:function(t){var e=this;t&&t.on(Xt,(function(t){var i=e.book.path.relative(t);e.display(i)}))}},{key:"injectStylesheet",value:function(t,e){var i=t.createElement("link");i.setAttribute("type","text/css"),i.setAttribute("rel","stylesheet"),i.setAttribute("href",this.settings.stylesheet),t.getElementsByTagName("head")[0].appendChild(i)}},{key:"injectScript",value:function(t,e){var i=t.createElement("script");i.setAttribute("type","text/javascript"),i.setAttribute("src",this.settings.script),i.textContent=" ",t.getElementsByTagName("head")[0].appendChild(i)}},{key:"injectIdentifier",value:function(t,e){var i=this.book.packaging.metadata.identifier,n=t.createElement("meta");n.setAttribute("name","dc.relation.ispartof"),i&&n.setAttribute("content",i),t.getElementsByTagName("head")[0].appendChild(n)}}],e&&Tn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();r()(En.prototype);var Pn=En,Ln=i(77256),_n=i.n(Ln);function On(t){return On="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},On(t)}function jn(t,e){for(var i=0;i-1?t:(this.path&&(i=this.path.resolve(t)),0!=e&&this.url&&(i=this.url.resolve(i)),i)}}},{key:"canonical",value:function(t){return t?this.settings.canonical?this.settings.canonical(t):this.resolve(t,!0):""}},{key:"determineType",value:function(t){var e;return"base64"===this.settings.encoding?$n:"string"!=typeof t?Zn:((e=new ht(t).path().extension)&&(e=e.replace(/\?.*$/,"")),e?"epub"===e?Gn:"opf"===e?"opf":"json"===e?Kn:void 0:"directory")}},{key:"unpack",value:function(t){var e=this;this.package=t,""===this.packaging.metadata.layout?this.load(this.url.resolve("META-INF/com.apple.ibooks.display-options.xml")).then((function(t){e.displayOptions=new Vn(t),e.loading.displayOptions.resolve(e.displayOptions)})).catch((function(t){e.displayOptions=new Vn,e.loading.displayOptions.resolve(e.displayOptions)})):(this.displayOptions=new Vn,this.loading.displayOptions.resolve(this.displayOptions)),this.spine.unpack(this.packaging,this.resolve.bind(this),this.canonical.bind(this)),this.resources=new Ge(this.packaging.manifest,{archive:this.archive,resolver:this.resolve.bind(this),request:this.request.bind(this),replacements:this.settings.replacements||(this.archived?"blobUrl":"base64")}),this.loadNavigation(this.packaging).then((function(){e.loading.navigation.resolve(e.navigation)})),this.packaging.coverPath&&(this.cover=this.resolve(this.packaging.coverPath)),this.loading.manifest.resolve(this.packaging.manifest),this.loading.metadata.resolve(this.packaging.metadata),this.loading.spine.resolve(this.spine),this.loading.cover.resolve(this.cover),this.loading.resources.resolve(this.resources),this.loading.pageList.resolve(this.pageList),this.isOpen=!0,this.archived||this.settings.replacements&&"none"!=this.settings.replacements?this.replacements().then((function(){e.loaded.displayOptions.then((function(){e.opening.resolve(e)}))})).catch((function(t){console.error(t)})):this.loaded.displayOptions.then((function(){e.opening.resolve(e)}))}},{key:"loadNavigation",value:function(t){var e=this,i=t.navPath||t.ncxPath,n=t.toc;return n?new Promise((function(i,s){e.navigation=new He(n),t.pageList&&(e.pageList=new ii(t.pageList)),i(e.navigation)})):i?this.load(i,"xml").then((function(t){return e.navigation=new He(t),e.pageList=new ii(t),e.navigation})):new Promise((function(t,i){e.navigation=new He,e.pageList=new ii,t(e.navigation)}))}},{key:"section",value:function(t){return this.spine.get(t)}},{key:"renderTo",value:function(t,e){return this.rendition=new Pn(this,e),this.rendition.attachTo(t),this.rendition}},{key:"setRequestCredentials",value:function(t){this.settings.requestCredentials=t}},{key:"setRequestHeaders",value:function(t){this.settings.requestHeaders=t}},{key:"unarchive",value:function(t,e){return this.archive=new Nn,this.archive.open(t,e)}},{key:"store",value:function(t){var e=this,i=this.settings.replacements&&"none"!==this.settings.replacements,n=this.url,s=this.settings.requestMethod||St.bind(this);return this.storage=new Fn(t,s,this.resolve.bind(this)),this.request=this.storage.request.bind(this.storage),this.opened.then((function(){e.archived&&(e.storage.requester=e.archive.request.bind(e.archive));var t=function(t,i){i.output=e.resources.substitute(t,i.url)};e.resources.settings.replacements=i||"blobUrl",e.resources.replacements().then((function(){return e.resources.replaceCss()})),e.storage.on("offline",(function(){e.url=new ht("/",""),e.spine.hooks.serialize.register(t)})),e.storage.on("online",(function(){e.url=n,e.spine.hooks.serialize.deregister(t)}))})),this.storage}},{key:"coverUrl",value:function(){var t=this;return this.loaded.cover.then((function(){return t.cover?t.archived?t.archive.createUrl(t.cover):t.cover:null}))}},{key:"replacements",value:function(){var t=this;return this.spine.hooks.serialize.register((function(e,i){i.output=t.resources.substitute(e,i.url)})),this.resources.replacements().then((function(){return t.resources.replaceCss()}))}},{key:"getRange",value:function(t){var e=new ft(t),i=this.spine.get(e.spinePos),n=this.load.bind(this);return i?i.load(n).then((function(t){return e.toRange(i.document)})):new Promise((function(t,e){e("CFI could not be found")}))}},{key:"key",value:function(t){var e=t||this.packaging.metadata.identifier||this.url.filename;return"epubjs:".concat(Mt,":").concat(e)}},{key:"destroy",value:function(){this.opened=void 0,this.loading=void 0,this.loaded=void 0,this.ready=void 0,this.isOpen=!1,this.isRendered=!1,this.spine&&this.spine.destroy(),this.locations&&this.locations.destroy(),this.pageList&&this.pageList.destroy(),this.archive&&this.archive.destroy(),this.resources&&this.resources.destroy(),this.container&&this.container.destroy(),this.packaging&&this.packaging.destroy(),this.rendition&&this.rendition.destroy(),this.displayOptions&&this.displayOptions.destroy(),this.spine=void 0,this.locations=void 0,this.pageList=void 0,this.archive=void 0,this.resources=void 0,this.container=void 0,this.packaging=void 0,this.rendition=void 0,this.navigation=void 0,this.url=void 0,this.path=void 0,this.archived=!1}}],e&&Yn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();r()(ts.prototype);var es=ts;function is(t,e){return new es(t,e)}is.VERSION=Mt,void 0!==i.g&&(i.g.EPUBJS_VERSION=Mt),is.Book=es,is.Rendition=Pn,is.Contents=Ci,is.CFI=ft,is.utils=n;var ns=is}}]);