@likecoin/epub-ts 0.3.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +64 -0
  2. package/dist/annotations.d.ts +159 -0
  3. package/dist/archive.d.ts +82 -0
  4. package/dist/book.d.ts +228 -0
  5. package/dist/container.d.ts +18 -0
  6. package/dist/contents.d.ts +351 -0
  7. package/dist/displayoptions.d.ts +20 -0
  8. package/dist/epub.cjs +10 -0
  9. package/dist/epub.cjs.map +1 -0
  10. package/dist/epub.d.ts +17 -0
  11. package/dist/epub.js +9500 -0
  12. package/dist/epub.js.map +1 -0
  13. package/dist/epub.umd.js +10 -0
  14. package/dist/epub.umd.js.map +1 -0
  15. package/dist/epubcfi.d.ts +116 -0
  16. package/dist/index.d.ts +8 -0
  17. package/dist/layout.d.ts +77 -0
  18. package/dist/locations.d.ts +117 -0
  19. package/dist/managers/continuous/index.d.ts +46 -0
  20. package/dist/managers/default/index.d.ts +117 -0
  21. package/dist/managers/helpers/snap.d.ts +63 -0
  22. package/dist/managers/helpers/stage.d.ts +41 -0
  23. package/dist/managers/helpers/views.d.ts +27 -0
  24. package/dist/managers/views/iframe.d.ts +114 -0
  25. package/dist/managers/views/inline.d.ts +65 -0
  26. package/dist/mapping.d.ts +97 -0
  27. package/dist/marks-pane/index.d.ts +40 -0
  28. package/dist/navigation.d.ts +108 -0
  29. package/dist/packaging.d.ts +104 -0
  30. package/dist/pagelist.d.ts +80 -0
  31. package/dist/rendition.d.ts +293 -0
  32. package/dist/resources.d.ts +97 -0
  33. package/dist/section.d.ts +88 -0
  34. package/dist/spine.d.ts +79 -0
  35. package/dist/store.d.ts +122 -0
  36. package/dist/themes.d.ts +103 -0
  37. package/dist/types.d.ts +269 -0
  38. package/dist/utils/constants.d.ts +59 -0
  39. package/dist/utils/core.d.ts +337 -0
  40. package/dist/utils/event-emitter.d.ts +6 -0
  41. package/dist/utils/hook.d.ts +30 -0
  42. package/dist/utils/mime.d.ts +5 -0
  43. package/dist/utils/path-utils.d.ts +14 -0
  44. package/dist/utils/path.d.ts +55 -0
  45. package/dist/utils/queue.d.ts +66 -0
  46. package/dist/utils/replacements.d.ts +11 -0
  47. package/dist/utils/request.d.ts +2 -0
  48. package/dist/utils/scrolltype.d.ts +2 -0
  49. package/dist/utils/url.d.ts +42 -0
  50. package/license +28 -0
  51. package/package.json +55 -0
package/dist/epub.cjs ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Cn=require("jszip");function Wt(h){const t=typeof h=="function"?h.prototype:h;return t.on=function(e,i){return this.__listeners||(this.__listeners={}),this.__listeners[e]||(this.__listeners[e]=[]),this.__listeners[e].push(i),this},t.off=function(e,i){return!this.__listeners||!this.__listeners[e]?this:(i?this.__listeners[e]=this.__listeners[e].filter(function(n){return n!==i}):delete this.__listeners[e],this)},t.emit=function(e){if(!this.__listeners||!this.__listeners[e])return;const i=Array.prototype.slice.call(arguments,1),n=this.__listeners[e].slice();for(let s=0;s<n.length;s++)n[s].apply(this,i)},h}var Oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Rn(h){return h&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")?h.default:h}var _e={},Gt={},Se={},Ei;function He(){if(Ei)return Se;Ei=1;function h(i,n){return n===void 0&&(n=Object),n&&typeof n.freeze=="function"?n.freeze(i):i}var t=h({HTML:"text/html",isHTML:function(i){return i===t.HTML},XML_APPLICATION:"application/xml",XML_TEXT:"text/xml",XML_XHTML_APPLICATION:"application/xhtml+xml",XML_SVG_IMAGE:"image/svg+xml"}),e=h({HTML:"http://www.w3.org/1999/xhtml",isHTML:function(i){return i===e.HTML},SVG:"http://www.w3.org/2000/svg",XML:"http://www.w3.org/XML/1998/namespace",XMLNS:"http://www.w3.org/2000/xmlns/"});return Se.freeze=h,Se.MIME_TYPE=t,Se.NAMESPACE=e,Se}var xi;function ki(){if(xi)return Gt;xi=1;var h=He(),t=h.NAMESPACE;function e(c){return c!==""}function i(c){return c?c.split(/[\t\n\f\r ]+/).filter(e):[]}function n(c,u){return c.hasOwnProperty(u)||(c[u]=!0),c}function s(c){if(!c)return[];var u=i(c);return Object.keys(u.reduce(n,{}))}function r(c){return function(u){return c&&c.indexOf(u)!==-1}}function o(c,u){for(var g in c)u[g]=c[g]}function l(c,u){var g=c.prototype;if(!(g instanceof u)){let x=function(){};x.prototype=u.prototype,x=new x,o(g,x),c.prototype=g=x}g.constructor!=c&&(typeof c!="function"&&console.error("unknown Class:"+c),g.constructor=c)}var f={},m=f.ELEMENT_NODE=1,b=f.ATTRIBUTE_NODE=2,E=f.TEXT_NODE=3,N=f.CDATA_SECTION_NODE=4,W=f.ENTITY_REFERENCE_NODE=5,T=f.ENTITY_NODE=6,D=f.PROCESSING_INSTRUCTION_NODE=7,q=f.COMMENT_NODE=8,U=f.DOCUMENT_NODE=9,$=f.DOCUMENT_TYPE_NODE=10,X=f.DOCUMENT_FRAGMENT_NODE=11,R=f.NOTATION_NODE=12,z={},P={};z.INDEX_SIZE_ERR=(P[1]="Index size error",1),z.DOMSTRING_SIZE_ERR=(P[2]="DOMString size error",2);var Y=z.HIERARCHY_REQUEST_ERR=(P[3]="Hierarchy request error",3);z.WRONG_DOCUMENT_ERR=(P[4]="Wrong document",4),z.INVALID_CHARACTER_ERR=(P[5]="Invalid character",5),z.NO_DATA_ALLOWED_ERR=(P[6]="No data allowed",6),z.NO_MODIFICATION_ALLOWED_ERR=(P[7]="No modification allowed",7);var _=z.NOT_FOUND_ERR=(P[8]="Not found",8);z.NOT_SUPPORTED_ERR=(P[9]="Not supported",9);var I=z.INUSE_ATTRIBUTE_ERR=(P[10]="Attribute in use",10);z.INVALID_STATE_ERR=(P[11]="Invalid state",11),z.SYNTAX_ERR=(P[12]="Syntax error",12),z.INVALID_MODIFICATION_ERR=(P[13]="Invalid modification",13),z.NAMESPACE_ERR=(P[14]="Invalid namespace",14),z.INVALID_ACCESS_ERR=(P[15]="Invalid access",15);function B(c,u){if(u instanceof Error)var g=u;else g=this,Error.call(this,P[c]),this.message=P[c],Error.captureStackTrace&&Error.captureStackTrace(this,B);return g.code=c,u&&(this.message=this.message+": "+u),g}B.prototype=Error.prototype,o(z,B);function F(){}F.prototype={length:0,item:function(c){return this[c]||null},toString:function(c,u){for(var g=[],x=0;x<this.length;x++)Vt(this[x],g,c,u);return g.join("")}};function V(c,u){this._node=c,this._refresh=u,Z(this)}function Z(c){var u=c._node._inc||c._node.ownerDocument._inc;if(c._inc!=u){var g=c._refresh(c._node);be(c,"length",g.length),o(g,c),c._inc=u}}V.prototype.item=function(c){return Z(this),this[c]},l(V,F);function G(){}function rt(c,u){for(var g=c.length;g--;)if(c[g]===u)return g}function H(c,u,g,x){if(x?u[rt(u,x)]=g:u[u.length++]=g,c){g.ownerElement=c;var k=c.ownerDocument;k&&(x&&dt(k,c,x),_t(k,c,g))}}function K(c,u,g){var x=rt(u,g);if(x>=0){for(var k=u.length-1;x<k;)u[x]=u[++x];if(u.length=k,c){var nt=c.ownerDocument;nt&&(dt(nt,c,g),g.ownerElement=null)}}else throw B(_,new Error(c.tagName+"@"+g))}G.prototype={length:0,item:F.prototype.item,getNamedItem:function(c){for(var u=this.length;u--;){var g=this[u];if(g.nodeName==c)return g}},setNamedItem:function(c){var u=c.ownerElement;if(u&&u!=this._ownerElement)throw new B(I);var g=this.getNamedItem(c.nodeName);return H(this._ownerElement,this,c,g),g},setNamedItemNS:function(c){var u=c.ownerElement,g;if(u&&u!=this._ownerElement)throw new B(I);return g=this.getNamedItemNS(c.namespaceURI,c.localName),H(this._ownerElement,this,c,g),g},removeNamedItem:function(c){var u=this.getNamedItem(c);return K(this._ownerElement,this,u),u},removeNamedItemNS:function(c,u){var g=this.getNamedItemNS(c,u);return K(this._ownerElement,this,g),g},getNamedItemNS:function(c,u){for(var g=this.length;g--;){var x=this[g];if(x.localName==u&&x.namespaceURI==c)return x}return null}};function Q(){}Q.prototype={hasFeature:function(c,u){return!0},createDocument:function(c,u,g){var x=new Ot;if(x.implementation=this,x.childNodes=new F,x.doctype=g||null,g&&x.appendChild(g),u){var k=x.createElementNS(c,u);x.appendChild(k)}return x},createDocumentType:function(c,u,g){var x=new ct;return x.name=c,x.nodeName=c,x.publicId=u||"",x.systemId=g||"",x}};function tt(){}tt.prototype={firstChild:null,lastChild:null,previousSibling:null,nextSibling:null,attributes:null,parentNode:null,childNodes:null,ownerDocument:null,nodeValue:null,namespaceURI:null,prefix:null,localName:null,insertBefore:function(c,u){return Et(this,c,u)},replaceChild:function(c,u){this.insertBefore(c,u),u&&this.removeChild(u)},removeChild:function(c){return ie(this,c)},appendChild:function(c){return this.insertBefore(c,null)},hasChildNodes:function(){return this.firstChild!=null},cloneNode:function(c){return he(this.ownerDocument||this,this,c)},normalize:function(){for(var c=this.firstChild;c;){var u=c.nextSibling;u&&u.nodeType==E&&c.nodeType==E?(this.removeChild(u),c.appendData(u.data)):(c.normalize(),c=u)}},isSupported:function(c,u){return this.ownerDocument.implementation.hasFeature(c,u)},hasAttributes:function(){return this.attributes.length>0},lookupPrefix:function(c){for(var u=this;u;){var g=u._nsMap;if(g){for(var x in g)if(g[x]==c)return x}u=u.nodeType==b?u.ownerDocument:u.parentNode}return null},lookupNamespaceURI:function(c){for(var u=this;u;){var g=u._nsMap;if(g&&c in g)return g[c];u=u.nodeType==b?u.ownerDocument:u.parentNode}return null},isDefaultNamespace:function(c){var u=this.lookupPrefix(c);return u==null}};function it(c){return c=="<"&&"&lt;"||c==">"&&"&gt;"||c=="&"&&"&amp;"||c=='"'&&"&quot;"||"&#"+c.charCodeAt()+";"}o(f,tt),o(f,tt.prototype);function pt(c,u){if(u(c))return!0;if(c=c.firstChild)do if(pt(c,u))return!0;while(c=c.nextSibling)}function Ot(){}function _t(c,u,g){c&&c._inc++;var x=g.namespaceURI;x===t.XMLNS&&(u._nsMap[g.prefix?g.localName:""]=g.value)}function dt(c,u,g,x){c&&c._inc++;var k=g.namespaceURI;k===t.XMLNS&&delete u._nsMap[g.prefix?g.localName:""]}function Qt(c,u,g){if(c&&c._inc){c._inc++;var x=u.childNodes;if(g)x[x.length++]=g;else{for(var k=u.firstChild,nt=0;k;)x[nt++]=k,k=k.nextSibling;x.length=nt}}}function ie(c,u){var g=u.previousSibling,x=u.nextSibling;return g?g.nextSibling=x:c.firstChild=x,x?x.previousSibling=g:c.lastChild=g,Qt(c.ownerDocument,c),u}function Et(c,u,g){var x=u.parentNode;if(x&&x.removeChild(u),u.nodeType===X){var k=u.firstChild;if(k==null)return u;var nt=u.lastChild}else k=nt=u;var gt=g?g.previousSibling:c.lastChild;k.previousSibling=gt,nt.nextSibling=g,gt?gt.nextSibling=k:c.firstChild=k,g==null?c.lastChild=nt:g.previousSibling=nt;do k.parentNode=c;while(k!==nt&&(k=k.nextSibling));return Qt(c.ownerDocument||c,c),u.nodeType==X&&(u.firstChild=u.lastChild=null),u}function Tt(c,u){var g=u.parentNode;if(g){var x=c.lastChild;g.removeChild(u);var x=c.lastChild}var x=c.lastChild;return u.parentNode=c,u.previousSibling=x,u.nextSibling=null,x?x.nextSibling=u:c.firstChild=u,c.lastChild=u,Qt(c.ownerDocument,c,u),u}Ot.prototype={nodeName:"#document",nodeType:U,doctype:null,documentElement:null,_inc:1,insertBefore:function(c,u){if(c.nodeType==X){for(var g=c.firstChild;g;){var x=g.nextSibling;this.insertBefore(g,u),g=x}return c}return this.documentElement==null&&c.nodeType==m&&(this.documentElement=c),Et(this,c,u),c.ownerDocument=this,c},removeChild:function(c){return this.documentElement==c&&(this.documentElement=null),ie(this,c)},importNode:function(c,u){return we(this,c,u)},getElementById:function(c){var u=null;return pt(this.documentElement,function(g){if(g.nodeType==m&&g.getAttribute("id")==c)return u=g,!0}),u},getElementsByClassName:function(c){var u=s(c);return new V(this,function(g){var x=[];return u.length>0&&pt(g.documentElement,function(k){if(k!==g&&k.nodeType===m){var nt=k.getAttribute("class");if(nt){var gt=c===nt;if(!gt){var Nt=s(nt);gt=u.every(r(Nt))}gt&&x.push(k)}}}),x})},createElement:function(c){var u=new Ct;u.ownerDocument=this,u.nodeName=c,u.tagName=c,u.localName=c,u.childNodes=new F;var g=u.attributes=new G;return g._ownerElement=u,u},createDocumentFragment:function(){var c=new kt;return c.ownerDocument=this,c.childNodes=new F,c},createTextNode:function(c){var u=new ne;return u.ownerDocument=this,u.appendData(c),u},createComment:function(c){var u=new vt;return u.ownerDocument=this,u.appendData(c),u},createCDATASection:function(c){var u=new St;return u.ownerDocument=this,u.appendData(c),u},createProcessingInstruction:function(c,u){var g=new at;return g.ownerDocument=this,g.tagName=g.target=c,g.nodeValue=g.data=u,g},createAttribute:function(c){var u=new qt;return u.ownerDocument=this,u.name=c,u.nodeName=c,u.localName=c,u.specified=!0,u},createEntityReference:function(c){var u=new Dt;return u.ownerDocument=this,u.nodeName=c,u},createElementNS:function(c,u){var g=new Ct,x=u.split(":"),k=g.attributes=new G;return g.childNodes=new F,g.ownerDocument=this,g.nodeName=u,g.tagName=u,g.namespaceURI=c,x.length==2?(g.prefix=x[0],g.localName=x[1]):g.localName=u,k._ownerElement=g,g},createAttributeNS:function(c,u){var g=new qt,x=u.split(":");return g.ownerDocument=this,g.nodeName=u,g.name=u,g.namespaceURI=c,g.specified=!0,x.length==2?(g.prefix=x[0],g.localName=x[1]):g.localName=u,g}},l(Ot,tt);function Ct(){this._nsMap={}}Ct.prototype={nodeType:m,hasAttribute:function(c){return this.getAttributeNode(c)!=null},getAttribute:function(c){var u=this.getAttributeNode(c);return u&&u.value||""},getAttributeNode:function(c){return this.attributes.getNamedItem(c)},setAttribute:function(c,u){var g=this.ownerDocument.createAttribute(c);g.value=g.nodeValue=""+u,this.setAttributeNode(g)},removeAttribute:function(c){var u=this.getAttributeNode(c);u&&this.removeAttributeNode(u)},appendChild:function(c){return c.nodeType===X?this.insertBefore(c,null):Tt(this,c)},setAttributeNode:function(c){return this.attributes.setNamedItem(c)},setAttributeNodeNS:function(c){return this.attributes.setNamedItemNS(c)},removeAttributeNode:function(c){return this.attributes.removeNamedItem(c.nodeName)},removeAttributeNS:function(c,u){var g=this.getAttributeNodeNS(c,u);g&&this.removeAttributeNode(g)},hasAttributeNS:function(c,u){return this.getAttributeNodeNS(c,u)!=null},getAttributeNS:function(c,u){var g=this.getAttributeNodeNS(c,u);return g&&g.value||""},setAttributeNS:function(c,u,g){var x=this.ownerDocument.createAttributeNS(c,u);x.value=x.nodeValue=""+g,this.setAttributeNode(x)},getAttributeNodeNS:function(c,u){return this.attributes.getNamedItemNS(c,u)},getElementsByTagName:function(c){return new V(this,function(u){var g=[];return pt(u,function(x){x!==u&&x.nodeType==m&&(c==="*"||x.tagName==c)&&g.push(x)}),g})},getElementsByTagNameNS:function(c,u){return new V(this,function(g){var x=[];return pt(g,function(k){k!==g&&k.nodeType===m&&(c==="*"||k.namespaceURI===c)&&(u==="*"||k.localName==u)&&x.push(k)}),x})}},Ot.prototype.getElementsByTagName=Ct.prototype.getElementsByTagName,Ot.prototype.getElementsByTagNameNS=Ct.prototype.getElementsByTagNameNS,l(Ct,tt);function qt(){}qt.prototype.nodeType=b,l(qt,tt);function Ft(){}Ft.prototype={data:"",substringData:function(c,u){return this.data.substring(c,c+u)},appendData:function(c){c=this.data+c,this.nodeValue=this.data=c,this.length=c.length},insertData:function(c,u){this.replaceData(c,0,u)},appendChild:function(c){throw new Error(P[Y])},deleteData:function(c,u){this.replaceData(c,u,"")},replaceData:function(c,u,g){var x=this.data.substring(0,c),k=this.data.substring(c+u);g=x+g+k,this.nodeValue=this.data=g,this.length=g.length}},l(Ft,tt);function ne(){}ne.prototype={nodeName:"#text",nodeType:E,splitText:function(c){var u=this.data,g=u.substring(c);u=u.substring(0,c),this.data=this.nodeValue=u,this.length=u.length;var x=this.ownerDocument.createTextNode(g);return this.parentNode&&this.parentNode.insertBefore(x,this.nextSibling),x}},l(ne,Ft);function vt(){}vt.prototype={nodeName:"#comment",nodeType:q},l(vt,Ft);function St(){}St.prototype={nodeName:"#cdata-section",nodeType:N},l(St,Ft);function ct(){}ct.prototype.nodeType=$,l(ct,tt);function Jt(){}Jt.prototype.nodeType=R,l(Jt,tt);function jt(){}jt.prototype.nodeType=T,l(jt,tt);function Dt(){}Dt.prototype.nodeType=W,l(Dt,tt);function kt(){}kt.prototype.nodeName="#document-fragment",kt.prototype.nodeType=X,l(kt,tt);function at(){}at.prototype.nodeType=D,l(at,tt);function yt(){}yt.prototype.serializeToString=function(c,u,g){return se.call(c,u,g)},tt.prototype.toString=se;function se(c,u){var g=[],x=this.nodeType==9&&this.documentElement||this,k=x.prefix,nt=x.namespaceURI;if(nt&&k==null){var k=x.lookupPrefix(nt);if(k==null)var gt=[{namespace:nt,prefix:null}]}return Vt(this,g,c,u,gt),g.join("")}function ye(c,u,g){var x=c.prefix||"",k=c.namespaceURI;if(!k||x==="xml"&&k===t.XML||k===t.XMLNS)return!1;for(var nt=g.length;nt--;){var gt=g[nt];if(gt.prefix===x)return gt.namespace!==k}return!0}function ae(c,u,g){c.push(" ",u,'="',g.replace(/[<&"]/g,it),'"')}function Vt(c,u,g,x,k){if(k||(k=[]),x)if(c=x(c),c){if(typeof c=="string"){u.push(c);return}}else return;switch(c.nodeType){case m:var nt=c.attributes,gt=nt.length,bt=c.firstChild,Nt=c.tagName;g=t.isHTML(c.namespaceURI)||g;var Ht=Nt;if(!g&&!c.prefix&&c.namespaceURI){for(var zt,wt=0;wt<nt.length;wt++)if(nt.item(wt).name==="xmlns"){zt=nt.item(wt).value;break}if(!zt)for(var Xt=k.length-1;Xt>=0;Xt--){var Yt=k[Xt];if(Yt.prefix===""&&Yt.namespace===c.namespaceURI){zt=Yt.namespace;break}}if(zt!==c.namespaceURI)for(var Xt=k.length-1;Xt>=0;Xt--){var Yt=k[Xt];if(Yt.namespace===c.namespaceURI){Yt.prefix&&(Ht=Yt.prefix+":"+Nt);break}}}u.push("<",Ht);for(var Bt=0;Bt<gt;Bt++){var Rt=nt.item(Bt);Rt.prefix=="xmlns"?k.push({prefix:Rt.localName,namespace:Rt.value}):Rt.nodeName=="xmlns"&&k.push({prefix:"",namespace:Rt.value})}for(var Bt=0;Bt<gt;Bt++){var Rt=nt.item(Bt);if(ye(Rt,g,k)){var $t=Rt.prefix||"",re=Rt.namespaceURI;ae(u,$t?"xmlns:"+$t:"xmlns",re),k.push({prefix:$t,namespace:re})}Vt(Rt,u,g,x,k)}if(Nt===Ht&&ye(c,g,k)){var $t=c.prefix||"",re=c.namespaceURI;ae(u,$t?"xmlns:"+$t:"xmlns",re),k.push({prefix:$t,namespace:re})}if(bt||g&&!/^(?:meta|link|img|br|hr|input)$/i.test(Nt)){if(u.push(">"),g&&/^script$/i.test(Nt))for(;bt;)bt.data?u.push(bt.data):Vt(bt,u,g,x,k.slice()),bt=bt.nextSibling;else for(;bt;)Vt(bt,u,g,x,k.slice()),bt=bt.nextSibling;u.push("</",Ht,">")}else u.push("/>");return;case U:case X:for(var bt=c.firstChild;bt;)Vt(bt,u,g,x,k.slice()),bt=bt.nextSibling;return;case b:return ae(u,c.name,c.value);case E:return u.push(c.data.replace(/[<&]/g,it).replace(/]]>/g,"]]&gt;"));case N:return u.push("<![CDATA[",c.data,"]]>");case q:return u.push("<!--",c.data,"-->");case $:var Ie=c.publicId,te=c.systemId;if(u.push("<!DOCTYPE ",c.name),Ie)u.push(" PUBLIC ",Ie),te&&te!="."&&u.push(" ",te),u.push(">");else if(te&&te!=".")u.push(" SYSTEM ",te,">");else{var Ae=c.internalSubset;Ae&&u.push(" [",Ae,"]"),u.push(">")}return;case D:return u.push("<?",c.target," ",c.data,"?>");case W:return u.push("&",c.nodeName,";");default:u.push("??",c.nodeName)}}function we(c,u,g){var x;switch(u.nodeType){case m:x=u.cloneNode(!1),x.ownerDocument=c;case X:break;case b:g=!0;break}if(x||(x=u.cloneNode(!1)),x.ownerDocument=c,x.parentNode=null,g)for(var k=u.firstChild;k;)x.appendChild(we(c,k,g)),k=k.nextSibling;return x}function he(c,u,g){var x=new u.constructor;for(var k in u){var nt=u[k];typeof nt!="object"&&nt!=x[k]&&(x[k]=nt)}switch(u.childNodes&&(x.childNodes=new F),x.ownerDocument=c,x.nodeType){case m:var gt=u.attributes,Nt=x.attributes=new G,Ht=gt.length;Nt._ownerElement=x;for(var zt=0;zt<Ht;zt++)x.setAttributeNode(he(c,gt.item(zt),!0));break;case b:g=!0}if(g)for(var wt=u.firstChild;wt;)x.appendChild(he(c,wt,g)),wt=wt.nextSibling;return x}function be(c,u,g){c[u]=g}try{if(Object.defineProperty){let c=function(u){switch(u.nodeType){case m:case X:var g=[];for(u=u.firstChild;u;)u.nodeType!==7&&u.nodeType!==8&&g.push(c(u)),u=u.nextSibling;return g.join("");default:return u.nodeValue}};Object.defineProperty(V.prototype,"length",{get:function(){return Z(this),this.$$length}}),Object.defineProperty(tt.prototype,"textContent",{get:function(){return c(this)},set:function(u){switch(this.nodeType){case m:case X:for(;this.firstChild;)this.removeChild(this.firstChild);(u||String(u))&&this.appendChild(this.ownerDocument.createTextNode(u));break;default:this.data=u,this.value=u,this.nodeValue=u}}}),be=function(u,g,x){u["$$"+g]=x}}}catch{}return Gt.DocumentType=ct,Gt.DOMException=B,Gt.DOMImplementation=Q,Gt.Element=Ct,Gt.Node=tt,Gt.NodeList=F,Gt.XMLSerializer=yt,Gt}var ce={},ei={},_i;function In(){return _i||(_i=1,(function(h){var t=He().freeze;h.XML_ENTITIES=t({amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}),h.HTML_ENTITIES=t({lt:"<",gt:">",amp:"&",quot:'"',apos:"'",Agrave:"À",Aacute:"Á",Acirc:"Â",Atilde:"Ã",Auml:"Ä",Aring:"Å",AElig:"Æ",Ccedil:"Ç",Egrave:"È",Eacute:"É",Ecirc:"Ê",Euml:"Ë",Igrave:"Ì",Iacute:"Í",Icirc:"Î",Iuml:"Ï",ETH:"Ð",Ntilde:"Ñ",Ograve:"Ò",Oacute:"Ó",Ocirc:"Ô",Otilde:"Õ",Ouml:"Ö",Oslash:"Ø",Ugrave:"Ù",Uacute:"Ú",Ucirc:"Û",Uuml:"Ü",Yacute:"Ý",THORN:"Þ",szlig:"ß",agrave:"à",aacute:"á",acirc:"â",atilde:"ã",auml:"ä",aring:"å",aelig:"æ",ccedil:"ç",egrave:"è",eacute:"é",ecirc:"ê",euml:"ë",igrave:"ì",iacute:"í",icirc:"î",iuml:"ï",eth:"ð",ntilde:"ñ",ograve:"ò",oacute:"ó",ocirc:"ô",otilde:"õ",ouml:"ö",oslash:"ø",ugrave:"ù",uacute:"ú",ucirc:"û",uuml:"ü",yacute:"ý",thorn:"þ",yuml:"ÿ",nbsp:" ",iexcl:"¡",cent:"¢",pound:"£",curren:"¤",yen:"¥",brvbar:"¦",sect:"§",uml:"¨",copy:"©",ordf:"ª",laquo:"«",not:"¬",shy:"­­",reg:"®",macr:"¯",deg:"°",plusmn:"±",sup2:"²",sup3:"³",acute:"´",micro:"µ",para:"¶",middot:"·",cedil:"¸",sup1:"¹",ordm:"º",raquo:"»",frac14:"¼",frac12:"½",frac34:"¾",iquest:"¿",times:"×",divide:"÷",forall:"∀",part:"∂",exist:"∃",empty:"∅",nabla:"∇",isin:"∈",notin:"∉",ni:"∋",prod:"∏",sum:"∑",minus:"−",lowast:"∗",radic:"√",prop:"∝",infin:"∞",ang:"∠",and:"∧",or:"∨",cap:"∩",cup:"∪",int:"∫",there4:"∴",sim:"∼",cong:"≅",asymp:"≈",ne:"≠",equiv:"≡",le:"≤",ge:"≥",sub:"⊂",sup:"⊃",nsub:"⊄",sube:"⊆",supe:"⊇",oplus:"⊕",otimes:"⊗",perp:"⊥",sdot:"⋅",Alpha:"Α",Beta:"Β",Gamma:"Γ",Delta:"Δ",Epsilon:"Ε",Zeta:"Ζ",Eta:"Η",Theta:"Θ",Iota:"Ι",Kappa:"Κ",Lambda:"Λ",Mu:"Μ",Nu:"Ν",Xi:"Ξ",Omicron:"Ο",Pi:"Π",Rho:"Ρ",Sigma:"Σ",Tau:"Τ",Upsilon:"Υ",Phi:"Φ",Chi:"Χ",Psi:"Ψ",Omega:"Ω",alpha:"α",beta:"β",gamma:"γ",delta:"δ",epsilon:"ε",zeta:"ζ",eta:"η",theta:"θ",iota:"ι",kappa:"κ",lambda:"λ",mu:"μ",nu:"ν",xi:"ξ",omicron:"ο",pi:"π",rho:"ρ",sigmaf:"ς",sigma:"σ",tau:"τ",upsilon:"υ",phi:"φ",chi:"χ",psi:"ψ",omega:"ω",thetasym:"ϑ",upsih:"ϒ",piv:"ϖ",OElig:"Œ",oelig:"œ",Scaron:"Š",scaron:"š",Yuml:"Ÿ",fnof:"ƒ",circ:"ˆ",tilde:"˜",ensp:" ",emsp:" ",thinsp:" ",zwnj:"‌",zwj:"‍",lrm:"‎",rlm:"‏",ndash:"–",mdash:"—",lsquo:"‘",rsquo:"’",sbquo:"‚",ldquo:"“",rdquo:"”",bdquo:"„",dagger:"†",Dagger:"‡",bull:"•",hellip:"…",permil:"‰",prime:"′",Prime:"″",lsaquo:"‹",rsaquo:"›",oline:"‾",euro:"€",trade:"™",larr:"←",uarr:"↑",rarr:"→",darr:"↓",harr:"↔",crarr:"↵",lceil:"⌈",rceil:"⌉",lfloor:"⌊",rfloor:"⌋",loz:"◊",spades:"♠",clubs:"♣",hearts:"♥",diams:"♦"}),h.entityMap=h.HTML_ENTITIES})(ei)),ei}var De={},Si;function An(){if(Si)return De;Si=1;var h=He().NAMESPACE,t=/[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,e=new RegExp("[\\-\\.0-9"+t.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]"),i=new RegExp("^"+t.source+e.source+"*(?::"+t.source+e.source+"*)?$"),n=0,s=1,r=2,o=3,l=4,f=5,m=6,b=7;function E(_,I){this.message=_,this.locator=I,Error.captureStackTrace&&Error.captureStackTrace(this,E)}E.prototype=new Error,E.prototype.name=E.name;function N(){}N.prototype={parse:function(_,I,B){var F=this.domBuilder;F.startDocument(),X(I,I={}),W(_,I,B,F,this.errorHandler),F.endDocument()}};function W(_,I,B,F,V){function Z(at){if(at>65535){at-=65536;var yt=55296+(at>>10),se=56320+(at&1023);return String.fromCharCode(yt,se)}else return String.fromCharCode(at)}function G(at){var yt=at.slice(1,-1);return yt in B?B[yt]:yt.charAt(0)==="#"?Z(parseInt(yt.substr(1).replace("x","0x"))):(V.error("entity not found:"+at),at)}function rt(at){if(at>_t){var yt=_.substring(_t,at).replace(/&#?\w+;/g,G);it&&H(_t),F.characters(yt,0,at-_t),_t=at}}function H(at,yt){for(;at>=Q&&(yt=tt.exec(_));)K=yt.index,Q=K+yt[0].length,it.lineNumber++;it.columnNumber=at-K+1}for(var K=0,Q=0,tt=/.*(?:\r\n?|\n)|.*$/g,it=F.locator,pt=[{currentNSMap:I}],Ot={},_t=0;;){try{var dt=_.indexOf("<",_t);if(dt<0){if(!_.substr(_t).match(/^\s*$/)){var Qt=F.doc,ie=Qt.createTextNode(_.substr(_t));Qt.appendChild(ie),F.currentElement=ie}return}switch(dt>_t&&rt(dt),_.charAt(dt+1)){case"/":var ct=_.indexOf(">",dt+3),Et=_.substring(dt+2,ct).replace(/[ \t\n\r]+$/g,""),Tt=pt.pop();ct<0?(Et=_.substring(dt+2).replace(/[\s<].*/,""),V.error("end tag name: "+Et+" is not complete:"+Tt.tagName),ct=dt+1+Et.length):Et.match(/\s</)&&(Et=Et.replace(/[\s<].*/,""),V.error("end tag name: "+Et+" maybe not complete"),ct=dt+1+Et.length);var Ct=Tt.localNSMap,qt=Tt.tagName==Et,Ft=qt||Tt.tagName&&Tt.tagName.toLowerCase()==Et.toLowerCase();if(Ft){if(F.endElement(Tt.uri,Tt.localName,Et),Ct)for(var ne in Ct)F.endPrefixMapping(ne);qt||V.fatalError("end tag name: "+Et+" is not match the current start tagName:"+Tt.tagName)}else pt.push(Tt);ct++;break;case"?":it&&H(dt),ct=z(_,dt,F);break;case"!":it&&H(dt),ct=R(_,dt,F,V);break;default:it&&H(dt);var vt=new P,St=pt[pt.length-1].currentNSMap,ct=D(_,dt,vt,St,G,V),Jt=vt.length;if(!vt.closed&&$(_,ct,vt.tagName,Ot)&&(vt.closed=!0,B.nbsp||V.warning("unclosed xml attribute")),it&&Jt){for(var jt=T(it,{}),Dt=0;Dt<Jt;Dt++){var kt=vt[Dt];H(kt.offset),kt.locator=T(it,{})}F.locator=jt,q(vt,F,St)&&pt.push(vt),F.locator=it}else q(vt,F,St)&&pt.push(vt);h.isHTML(vt.uri)&&!vt.closed?ct=U(_,ct,vt.tagName,G,F):ct++}}catch(at){if(at instanceof E)throw at;V.error("element parse error: "+at),ct=-1}ct>_t?_t=ct:rt(Math.max(dt,_t)+1)}}function T(_,I){return I.lineNumber=_.lineNumber,I.columnNumber=_.columnNumber,I}function D(_,I,B,F,V,Z){function G(it,pt,Ot){B.attributeNames.hasOwnProperty(it)&&Z.fatalError("Attribute "+it+" redefined"),B.addValue(it,pt,Ot)}for(var rt,H,K=++I,Q=n;;){var tt=_.charAt(K);switch(tt){case"=":if(Q===s)rt=_.slice(I,K),Q=o;else if(Q===r)Q=o;else throw new Error("attribute equal must after attrName");break;case"'":case'"':if(Q===o||Q===s)if(Q===s&&(Z.warning('attribute value must after "="'),rt=_.slice(I,K)),I=K+1,K=_.indexOf(tt,I),K>0)H=_.slice(I,K).replace(/&#?\w+;/g,V),G(rt,H,I-1),Q=f;else throw new Error("attribute value no end '"+tt+"' match");else if(Q==l)H=_.slice(I,K).replace(/&#?\w+;/g,V),G(rt,H,I),Z.warning('attribute "'+rt+'" missed start quot('+tt+")!!"),I=K+1,Q=f;else throw new Error('attribute value must after "="');break;case"/":switch(Q){case n:B.setTagName(_.slice(I,K));case f:case m:case b:Q=b,B.closed=!0;case l:case s:case r:break;default:throw new Error("attribute invalid close char('/')")}break;case"":return Z.error("unexpected end of input"),Q==n&&B.setTagName(_.slice(I,K)),K;case">":switch(Q){case n:B.setTagName(_.slice(I,K));case f:case m:case b:break;case l:case s:H=_.slice(I,K),H.slice(-1)==="/"&&(B.closed=!0,H=H.slice(0,-1));case r:Q===r&&(H=rt),Q==l?(Z.warning('attribute "'+H+'" missed quot(")!'),G(rt,H.replace(/&#?\w+;/g,V),I)):((!h.isHTML(F[""])||!H.match(/^(?:disabled|checked|selected)$/i))&&Z.warning('attribute "'+H+'" missed value!! "'+H+'" instead!!'),G(H,H,I));break;case o:throw new Error("attribute value missed!!")}return K;case"€":tt=" ";default:if(tt<=" ")switch(Q){case n:B.setTagName(_.slice(I,K)),Q=m;break;case s:rt=_.slice(I,K),Q=r;break;case l:var H=_.slice(I,K).replace(/&#?\w+;/g,V);Z.warning('attribute "'+H+'" missed quot(")!!'),G(rt,H,I);case f:Q=m;break}else switch(Q){case r:B.tagName,(!h.isHTML(F[""])||!rt.match(/^(?:disabled|checked|selected)$/i))&&Z.warning('attribute "'+rt+'" missed value!! "'+rt+'" instead2!!'),G(rt,rt,I),I=K,Q=s;break;case f:Z.warning('attribute space is required"'+rt+'"!!');case m:Q=s,I=K;break;case o:Q=l,I=K;break;case b:throw new Error("elements closed character '/' and '>' must be connected to")}}K++}}function q(_,I,B){for(var F=_.tagName,V=null,tt=_.length;tt--;){var Z=_[tt],G=Z.qName,rt=Z.value,it=G.indexOf(":");if(it>0)var H=Z.prefix=G.slice(0,it),K=G.slice(it+1),Q=H==="xmlns"&&K;else K=G,H=null,Q=G==="xmlns"&&"";Z.localName=K,Q!==!1&&(V==null&&(V={},X(B,B={})),B[Q]=V[Q]=rt,Z.uri=h.XMLNS,I.startPrefixMapping(Q,rt))}for(var tt=_.length;tt--;){Z=_[tt];var H=Z.prefix;H&&(H==="xml"&&(Z.uri=h.XML),H!=="xmlns"&&(Z.uri=B[H||""]))}var it=F.indexOf(":");it>0?(H=_.prefix=F.slice(0,it),K=_.localName=F.slice(it+1)):(H=null,K=_.localName=F);var pt=_.uri=B[H||""];if(I.startElement(pt,K,F,_),_.closed){if(I.endElement(pt,K,F),V)for(H in V)I.endPrefixMapping(H)}else return _.currentNSMap=B,_.localNSMap=V,!0}function U(_,I,B,F,V){if(/^(?:script|textarea)$/i.test(B)){var Z=_.indexOf("</"+B+">",I),G=_.substring(I+1,Z);if(/[&<]/.test(G))return/^script$/i.test(B)?(V.characters(G,0,G.length),Z):(G=G.replace(/&#?\w+;/g,F),V.characters(G,0,G.length),Z)}return I+1}function $(_,I,B,F){var V=F[B];return V==null&&(V=_.lastIndexOf("</"+B+">"),V<I&&(V=_.lastIndexOf("</"+B)),F[B]=V),V<I}function X(_,I){for(var B in _)I[B]=_[B]}function R(_,I,B,F){var V=_.charAt(I+2);switch(V){case"-":if(_.charAt(I+3)==="-"){var Z=_.indexOf("-->",I+4);return Z>I?(B.comment(_,I+4,Z-I-4),Z+3):(F.error("Unclosed comment"),-1)}else return-1;default:if(_.substr(I+3,6)=="CDATA["){var Z=_.indexOf("]]>",I+9);return B.startCDATA(),B.characters(_,I+9,Z-I-9),B.endCDATA(),Z+3}var G=Y(_,I),rt=G.length;if(rt>1&&/!doctype/i.test(G[0][0])){var H=G[1][0],K=!1,Q=!1;rt>3&&(/^public$/i.test(G[2][0])?(K=G[3][0],Q=rt>4&&G[4][0]):/^system$/i.test(G[2][0])&&(Q=G[3][0]));var tt=G[rt-1];return B.startDTD(H,K,Q),B.endDTD(),tt.index+tt[0].length}}return-1}function z(_,I,B){var F=_.indexOf("?>",I);if(F){var V=_.substring(I,F).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);return V?(V[0].length,B.processingInstruction(V[1],V[2]),F+2):-1}return-1}function P(){this.attributeNames={}}P.prototype={setTagName:function(_){if(!i.test(_))throw new Error("invalid tagName:"+_);this.tagName=_},addValue:function(_,I,B){if(!i.test(_))throw new Error("invalid attribute:"+_);this.attributeNames[_]=this.length,this[this.length++]={qName:_,value:I,offset:B}},length:0,getLocalName:function(_){return this[_].localName},getLocator:function(_){return this[_].locator},getQName:function(_){return this[_].qName},getURI:function(_){return this[_].uri},getValue:function(_){return this[_].value}};function Y(_,I){var B,F=[],V=/'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;for(V.lastIndex=I,V.exec(_);B=V.exec(_);)if(F.push(B),B[1])return F}return De.XMLReader=N,De.ParseError=E,De}var Ti;function Ln(){if(Ti)return ce;Ti=1;var h=He(),t=ki(),e=In(),i=An(),n=t.DOMImplementation,s=h.NAMESPACE,r=i.ParseError,o=i.XMLReader;function l(T){this.options=T||{locator:{}}}l.prototype.parseFromString=function(T,D){var q=this.options,U=new o,$=q.domBuilder||new m,X=q.errorHandler,R=q.locator,z=q.xmlns||{},P=/\/x?html?$/.test(D),Y=P?e.HTML_ENTITIES:e.XML_ENTITIES;return R&&$.setDocumentLocator(R),U.errorHandler=f(X,$,R),U.domBuilder=q.domBuilder||$,P&&(z[""]=s.HTML),z.xml=z.xml||s.XML,T&&typeof T=="string"?U.parse(T,z,Y):U.errorHandler.error("invalid doc source"),$.doc};function f(T,D,q){if(!T){if(D instanceof m)return D;T=D}var U={},$=T instanceof Function;q=q||{};function X(R){var z=T[R];!z&&$&&(z=T.length==2?function(P){T(R,P)}:T),U[R]=z&&function(P){z("[xmldom "+R+"] "+P+E(q))}||function(){}}return X("warning"),X("error"),X("fatalError"),U}function m(){this.cdata=!1}function b(T,D){D.lineNumber=T.lineNumber,D.columnNumber=T.columnNumber}m.prototype={startDocument:function(){this.doc=new n().createDocument(null,null,null),this.locator&&(this.doc.documentURI=this.locator.systemId)},startElement:function(T,D,q,U){var $=this.doc,X=$.createElementNS(T,q||D),R=U.length;W(this,X),this.currentElement=X,this.locator&&b(this.locator,X);for(var z=0;z<R;z++){var T=U.getURI(z),P=U.getValue(z),q=U.getQName(z),Y=$.createAttributeNS(T,q);this.locator&&b(U.getLocator(z),Y),Y.value=Y.nodeValue=P,X.setAttributeNode(Y)}},endElement:function(T,D,q){var U=this.currentElement;U.tagName,this.currentElement=U.parentNode},startPrefixMapping:function(T,D){},endPrefixMapping:function(T){},processingInstruction:function(T,D){var q=this.doc.createProcessingInstruction(T,D);this.locator&&b(this.locator,q),W(this,q)},ignorableWhitespace:function(T,D,q){},characters:function(T,D,q){if(T=N.apply(this,arguments),T){if(this.cdata)var U=this.doc.createCDATASection(T);else var U=this.doc.createTextNode(T);this.currentElement?this.currentElement.appendChild(U):/^\s*$/.test(T)&&this.doc.appendChild(U),this.locator&&b(this.locator,U)}},skippedEntity:function(T){},endDocument:function(){this.doc.normalize()},setDocumentLocator:function(T){(this.locator=T)&&(T.lineNumber=0)},comment:function(T,D,q){T=N.apply(this,arguments);var U=this.doc.createComment(T);this.locator&&b(this.locator,U),W(this,U)},startCDATA:function(){this.cdata=!0},endCDATA:function(){this.cdata=!1},startDTD:function(T,D,q){var U=this.doc.implementation;if(U&&U.createDocumentType){var $=U.createDocumentType(T,D,q);this.locator&&b(this.locator,$),W(this,$),this.doc.doctype=$}},warning:function(T){console.warn("[xmldom warning] "+T,E(this.locator))},error:function(T){console.error("[xmldom error] "+T,E(this.locator))},fatalError:function(T){throw new r(T,this.locator)}};function E(T){if(T)return`
2
+ @`+(T.systemId||"")+"#[line:"+T.lineNumber+",col:"+T.columnNumber+"]"}function N(T,D,q){return typeof T=="string"?T.substr(D,q):T.length>=D+q||D?new java.lang.String(T,D,q)+"":T}"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(T){m.prototype[T]=function(){return null}});function W(T,D){T.currentElement?T.currentElement.appendChild(D):T.doc.appendChild(D)}return ce.__DOMHandler=m,ce.DOMParser=l,ce.DOMImplementation=t.DOMImplementation,ce.XMLSerializer=t.XMLSerializer,ce}var Ni;function On(){if(Ni)return _e;Ni=1;var h=ki();return _e.DOMImplementation=h.DOMImplementation,_e.XMLSerializer=h.XMLSerializer,_e.DOMParser=Ln().DOMParser,_e}var Pi=On();const di=typeof window<"u"?window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame:!1,Dn=1,kn=3,Mi=typeof URL<"u"?URL:typeof window<"u"?window.URL||window.webkitURL||window.mozURL:void 0;function Xe(){let h=new Date().getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const i=(h+Math.random()*16)%16|0;return h=Math.floor(h/16),(e=="x"?i:i&7|8).toString(16)})}function Pn(){return Math.max(document.documentElement.clientHeight,document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight)}function zi(h){return!!(h&&h.nodeType==1)}function ut(h){return!isNaN(parseFloat(h))&&isFinite(h)}function Bi(h){const t=parseFloat(h);return ut(h)===!1?!1:typeof h=="string"&&h.indexOf(".")>-1?!0:Math.floor(t)!==t}function de(h){const t=["Webkit","webkit","Moz","O","ms"],e=["-webkit-","-webkit-","-moz-","-o-","-ms-"],i=h.toLowerCase(),n=t.length;if(typeof document>"u"||typeof document.body.style[i]<"u")return h;for(let s=0;s<n;s++)if(typeof document.body.style[e[s]+i]<"u")return e[s]+i;return h}function Ui(h,...t){for(let e=1,i=arguments.length;e<i;e++){const n=arguments[e];for(const s in n)h[s]===void 0&&(h[s]=n[s])}return h}function xt(h,...t){return[].slice.call(arguments,1).forEach(function(i){i&&Object.getOwnPropertyNames(i).forEach(function(n){Object.defineProperty(h,n,Object.getOwnPropertyDescriptor(i,n))})}),h}function Mn(h,t,e){const i=me(h,t,e);return t.splice(i,0,h),i}function me(h,t,e,i,n){const s=i||0,r=n||t.length,o=parseInt(s+(r-s)/2);if(e||(e=function(f,m){return f>m?1:f<m?-1:0}),r-s<=0)return o;const l=e(t[o],h);return r-s===1?l>=0?o:o+1:l===0?o:l===-1?me(h,t,e,o,r):me(h,t,e,s,o)}function ze(h,t,e,i,n){const s=i||0,r=n||t.length,o=parseInt(s+(r-s)/2);if(e||(e=function(f,m){return f>m?1:f<m?-1:0}),r-s<=0)return-1;const l=e(t[o],h);return r-s===1?l===0?o:-1:l===0?o:l===-1?ze(h,t,e,o,r):ze(h,t,e,s,o)}function Pe(h){const t=window.getComputedStyle(h),e=["width","paddingRight","paddingLeft","marginRight","marginLeft","borderRightWidth","borderLeftWidth"],i=["height","paddingTop","paddingBottom","marginTop","marginBottom","borderTopWidth","borderBottomWidth"];let n=0,s=0;return e.forEach(function(r){n+=parseFloat(t[r])||0}),i.forEach(function(r){s+=parseFloat(t[r])||0}),{height:s,width:n}}function Be(h){const t=window.getComputedStyle(h),e=["paddingRight","paddingLeft","marginRight","marginLeft","borderRightWidth","borderLeftWidth"],i=["paddingTop","paddingBottom","marginTop","marginBottom","borderTopWidth","borderBottomWidth"];let n=0,s=0;return e.forEach(function(r){n+=parseFloat(t[r])||0}),i.forEach(function(r){s+=parseFloat(t[r])||0}),{height:s,width:n}}function oi(h){let t;const e=h.ownerDocument;if(h.nodeType==Node.TEXT_NODE){const i=e.createRange();i.selectNodeContents(h),t=i.getBoundingClientRect()}else t=h.getBoundingClientRect();return t}function Ue(){const h=window.innerWidth,t=window.innerHeight;return{top:0,left:0,right:h,bottom:t,width:h,height:t}}function fi(h,t){const i=h.parentNode.childNodes;let n,s=-1;for(let r=0;r<i.length&&(n=i[r],n.nodeType===t&&s++,n!=h);r++);return s}function zn(h){return fi(h,kn)}function Wi(h){return fi(h,Dn)}function Ne(h){return["xml","opf","ncx"].indexOf(h)>-1}function qi(h,t){return new Blob([h],{type:t})}function We(h,t){const e=qi(h,t);return Mi.createObjectURL(e)}function Fi(h){return Mi.revokeObjectURL(h)}function ai(h,t){if(typeof h!="string")return;const e=btoa(h);return"data:"+t+";base64,"+e}function ji(h){return Object.prototype.toString.call(h).slice(8,-1)}function Ut(h,t,e){let i;return typeof DOMParser>"u"||e?i=Pi.DOMParser:i=DOMParser,h.charCodeAt(0)===65279&&(h=h.slice(1)),new i().parseFromString(h,t)}function lt(h,t){let e;if(!h)throw new Error("No Element Provided");if(typeof h.querySelector<"u")return h.querySelector(t)??void 0;if(e=h.getElementsByTagName(t),e.length)return e[0]}function Kt(h,t){return typeof h.querySelector<"u"?h.querySelectorAll(t):h.getElementsByTagName(t)}function fe(h,t,e){let i,n;if(typeof h.querySelector<"u"){t+="[";for(const s in e)t+=s+"~='"+e[s]+"'";return t+="]",h.querySelector(t)??void 0}else if(i=h.getElementsByTagName(t),n=Array.prototype.slice.call(i,0).filter(function(s){for(const r in e)if(s.getAttribute(r)===e[r])return!0;return!1}),n)return n[0]}function qe(h,t){typeof(h.ownerDocument||h).createTreeWalker<"u"?Vi(h,t,NodeFilter.SHOW_TEXT):pi(h,function(i){return i&&i.nodeType===3&&t(i),!1})}function Vi(h,t,e){const i=document.createTreeWalker(h,e,null);let n;for(;n=i.nextNode();)t(n)}function pi(h,t,e){if(t(h))return!0;let i=h.firstChild;if(i)do{if(pi(i,t))return!0;i=i.nextSibling}while(i)}function Hi(h){return new Promise(function(t,e){const i=new FileReader;i.readAsDataURL(h),i.onloadend=function(){t(i.result)}})}class st{constructor(){this.id=Xe(),this.promise=new Promise((t,e)=>{this.resolve=t,this.reject=e}),Object.freeze(this)}}function Fe(h,t,e){let i;if(typeof h.querySelector<"u"&&(i=h.querySelector(`${t}[*|type="${e}"]`)),!i||i.length===0){i=Kt(h,t);for(let n=0;n<i.length;n++)if(i[n].getAttributeNS("http://www.idpf.org/2007/ops","type")===e||i[n].getAttribute("epub:type")===e)return i[n]}else return i}function hi(h){const t=[],e=h.childNodes;for(let i=0;i<e.length;i++){const n=e[i];n.nodeType===1&&t.push(n)}return t}function li(h){const t=[];for(let e=h??null;e;e=e.parentNode)t.unshift(e);return t}function pe(h,t,e){const i=[],n=h.childNodes;for(let s=0;s<n.length;s++){const r=n[s];if(r.nodeType===1&&r.nodeName.toLowerCase()===t){if(e)return r;i.push(r)}}if(!e)return i}function Bn(h,t){let e;if(!(h===null||t===""))for(e=h.parentNode;e&&e.nodeType===1;){if(e.tagName.toLowerCase()===t)return e;e=e.parentNode}}class Xi{constructor(){this.collapsed=!1,this.commonAncestorContainer=void 0,this.endContainer=void 0,this.endOffset=void 0,this.startContainer=void 0,this.startOffset=void 0}setStart(t,e){this.startContainer=t,this.startOffset=e,this.endContainer?this.commonAncestorContainer=this._commonAncestorContainer():this.collapse(!0),this._checkCollapsed()}setEnd(t,e){this.endContainer=t,this.endOffset=e,this.startContainer?(this.collapsed=!1,this.commonAncestorContainer=this._commonAncestorContainer()):this.collapse(!1),this._checkCollapsed()}collapse(t){var e,i;this.collapsed=!0,t?(this.endContainer=this.startContainer,this.endOffset=this.startOffset,this.commonAncestorContainer=((e=this.startContainer)==null?void 0:e.parentNode)??void 0):(this.startContainer=this.endContainer,this.startOffset=this.endOffset,this.commonAncestorContainer=((i=this.endContainer)==null?void 0:i.parentNode)??void 0)}selectNode(t){const e=t.parentNode,i=Array.prototype.indexOf.call(e.childNodes,t);this.setStart(e,i),this.setEnd(e,i+1)}selectNodeContents(t){const e=t.nodeType===3?(t.textContent??"").length:t.childNodes.length;this.setStart(t,0),this.setEnd(t,e)}_commonAncestorContainer(t,e){const i=li(t??this.startContainer),n=li(e??this.endContainer);if(i[0]==n[0]){for(let s=0;s<i.length;s++)if(i[s]!=n[s])return i[s-1]}}_checkCollapsed(){this.startContainer===this.endContainer&&this.startOffset===this.endOffset?this.collapsed=!0:this.collapsed=!1}toString(){return""}}const Un=Object.freeze(Object.defineProperty({__proto__:null,RangeObject:Xi,blob2base64:Hi,borders:Be,bounds:Pe,createBase64Url:ai,createBlob:qi,createBlobUrl:We,defaults:Ui,defer:st,documentHeight:Pn,extend:xt,filterChildren:pe,findChildren:hi,getParentByTagName:Bn,indexOfElementNode:Wi,indexOfNode:fi,indexOfSorted:ze,indexOfTextNode:zn,insert:Mn,isElement:zi,isFloat:Bi,isNumber:ut,isXml:Ne,locationOf:me,nodeBounds:oi,parents:li,parse:Ut,prefixed:de,qs:lt,qsa:Kt,qsp:fe,querySelectorByType:Fe,requestAnimationFrame:di,revokeBlobUrl:Fi,sprint:qe,treeWalker:Vi,type:ji,uuid:Xe,walk:pi,windowBounds:Ue},Symbol.toStringTag,{value:"Module"}));function ve(h){if(typeof h!="string")throw new TypeError("Path must be a string. Received "+h)}function Wn(h,t){let e="",i=-1,n=0,s;for(let r=0;r<=h.length;++r){if(r<h.length)s=h.charCodeAt(r);else{if(s===47)break;s=47}if(s===47){if(!(i===r-1||n===1))if(i!==r-1&&n===2){if(e.length<2||e.charCodeAt(e.length-1)!==46||e.charCodeAt(e.length-2)!==46){if(e.length>2){const o=e.length-1;let l=o;for(;l>=0&&e.charCodeAt(l)!==47;--l);if(l!==o){l===-1?e="":e=e.slice(0,l),i=r,n=0;continue}}else if(e.length===2||e.length===1){e="",i=r,n=0;continue}}t&&(e.length>0?e+="/..":e="..")}else e.length>0?e+="/"+h.slice(i+1,r):e=h.slice(i+1,r);i=r,n=0}else s===46&&n!==-1?++n:n=-1}return e}function ci(...h){let t="",e=!1;for(let i=arguments.length-1;i>=-1&&!e;i--){let n;i>=0?n=arguments[i]:n="/",ve(n),n.length!==0&&(t=n+"/"+t,e=n.charCodeAt(0)===47)}return t=Wn(t,!e),e?t.length>0?"/"+t:"/":t.length>0?t:"."}function qn(h,t){if(ve(h),ve(t),h===t||(h=ci(h),t=ci(t),h===t))return"";let e=1;for(;e<h.length&&h.charCodeAt(e)===47;++e);const i=h.length,n=i-e;let s=1;for(;s<t.length&&t.charCodeAt(s)===47;++s);const o=t.length-s,l=n<o?n:o;let f=-1,m=0;for(;m<=l;++m){if(m===l){if(o>l){if(t.charCodeAt(s+m)===47)return t.slice(s+m+1);if(m===0)return t.slice(s+m)}else n>l&&(h.charCodeAt(e+m)===47?f=m:m===0&&(f=0));break}const E=h.charCodeAt(e+m),N=t.charCodeAt(s+m);if(E!==N)break;E===47&&(f=m)}let b="";for(m=e+f+1;m<=i;++m)(m===i||h.charCodeAt(m)===47)&&(b.length===0?b+="..":b+="/..");return b.length>0?b+t.slice(s+f):(s+=f,t.charCodeAt(s)===47&&++s,t.slice(s))}function Fn(h){if(ve(h),h.length===0)return".";let t=h.charCodeAt(0);const e=t===47;let i=-1,n=!0;for(let s=h.length-1;s>=1;--s)if(t=h.charCodeAt(s),t===47){if(!n){i=s;break}}else n=!1;return i===-1?e?"/":".":e&&i===1?"//":h.slice(0,i)}function jn(h){return ve(h),h.length>0&&h.charCodeAt(0)===47}function Vn(h){ve(h);const t={root:"",dir:"",base:"",ext:"",name:""};if(h.length===0)return t;let e=h.charCodeAt(0);const i=e===47;let n;i?(t.root="/",n=1):n=0;let s=-1,r=0,o=-1,l=!0,f=h.length-1,m=0;for(;f>=n;--f){if(e=h.charCodeAt(f),e===47){if(!l){r=f+1;break}continue}o===-1&&(l=!1,o=f+1),e===46?s===-1?s=f:m!==1&&(m=1):s!==-1&&(m=-1)}return s===-1||o===-1||m===0||m===1&&s===o-1&&s===r+1?o!==-1&&(r===0&&i?t.base=t.name=h.slice(1,o):t.base=t.name=h.slice(r,o)):(r===0&&i?(t.name=h.slice(1,s),t.base=h.slice(1,o)):(t.name=h.slice(r,s),t.base=h.slice(r,o)),t.ext=h.slice(s,o)),r>0?t.dir=h.slice(0,r-1):i&&(t.dir="/"),t}const ee={resolve:ci,relative:qn,dirname:Fn,isAbsolute:jn,parse:Vn};class Zt{constructor(t){t.indexOf("://")>-1&&(t=new URL(t).pathname);const i=this.parse(t);this.path=t,this.isDirectory(t)?(this.directory=t,this.filename="",this.extension=""):(this.directory=i.dir+"/",this.filename=i.base,this.extension=i.ext.slice(1))}parse(t){return ee.parse(t)}isAbsolute(t){return ee.isAbsolute(t||this.path)}isDirectory(t){return t.charAt(t.length-1)==="/"}resolve(t){return ee.resolve(this.directory,t)}relative(t){return t&&t.indexOf("://")>-1?t:ee.relative(this.directory,t)}splitPath(t){return this.splitPathRe.exec(t).slice(1)}toString(){return this.path}}class Pt{constructor(t,e){const i=t.indexOf("://")>-1;let n=t,s;if(this.Url=void 0,this.href=t,this.protocol="",this.origin="",this.hash="",this.hash="",this.search="",this.base=e,!i&&e!==!1&&typeof e!="string"&&window&&window.location&&(this.base=window.location.href),i||this.base)try{this.base?this.Url=new URL(t,this.base):this.Url=new URL(t),this.href=this.Url.href,this.protocol=this.Url.protocol,this.origin=this.Url.origin,this.origin==="null"&&this.protocol==="file:"&&(this.origin="file://"),this.hash=this.Url.hash,this.search=this.Url.search,n=this.Url.pathname+(this.Url.search?this.Url.search:"")}catch{this.Url=void 0,this.base&&(s=new Zt(this.base),n=s.resolve(n))}this.Path=new Zt(n),this.directory=this.Path.directory,this.filename=this.Path.filename,this.extension=this.Path.extension}path(){return this.Path}resolve(t){if(t.indexOf("://")>-1)return t;const i=ee.resolve(this.directory,t);return this.origin+i}relative(t){return ee.relative(t,this.directory)}toString(){return this.href}}const ue=1,At=3,Hn=9;class et{constructor(t,e,i){if(this.str="",this.base={},this.spinePos=0,this.range=!1,this.path={},this.start=null,this.end=null,!(this instanceof et))return new et(t,e,i);typeof e=="string"?this.base=this.parseComponent(e):typeof e=="object"&&e.steps&&(this.base=e);const n=this.checkType(t);if(n==="string")return this.str=t,xt(this,this.parse(t));if(n==="range")return xt(this,this.fromRange(t,this.base,i));if(n==="node")return xt(this,this.fromNode(t,this.base,i));if(n==="EpubCFI"&&t.path)return t;if(t)throw new TypeError("not a valid argument for EpubCFI");return this}checkType(t){return this.isCfiString(t)?"string":t&&typeof t=="object"&&(ji(t)==="Range"||typeof t.startContainer<"u")?"range":t&&typeof t=="object"&&typeof t.nodeType<"u"?"node":t&&typeof t=="object"&&t instanceof et?"EpubCFI":!1}parse(t){const e={spinePos:-1,range:!1,base:{},path:{},start:null,end:null};if(typeof t!="string")return{spinePos:-1};t.indexOf("epubcfi(")===0&&t[t.length-1]===")"&&(t=t.slice(8,t.length-1));const i=this.getChapterComponent(t);if(!i)return{spinePos:-1};e.base=this.parseComponent(i);const n=this.getPathComponent(t);e.path=this.parseComponent(n);const s=this.getRange(t);return s&&(e.range=!0,e.start=this.parseComponent(s[0]),e.end=this.parseComponent(s[1])),e.spinePos=e.base.steps[1].index,e}parseComponent(t){const e={steps:[],terminal:{offset:null,assertion:null}},i=t.split(":"),n=i[0].split("/");let s;return i.length>1&&(s=i[1],e.terminal=this.parseTerminal(s)),n[0]===""&&n.shift(),e.steps=n.map((function(r){return this.parseStep(r)}).bind(this)),e}parseStep(t){let e,i,n;const s=t.match(/\[(.*)\]/);s&&s[1]&&(n=s[1]);const r=parseInt(t);if(!isNaN(r))return r%2===0?(e="element",i=r/2-1):(e="text",i=(r-1)/2),{type:e,index:i,id:n||null,tagName:""}}parseTerminal(t){let e,i=null;const n=t.match(/\[(.*)\]/);return n&&n[1]?(e=parseInt(t.split("[")[0]),i=n[1]):e=parseInt(t),ut(e)||(e=null),{offset:e,assertion:i}}getChapterComponent(t){return t.split("!")[0]}getPathComponent(t){const e=t.split("!");if(e[1])return e[1].split(",")[0]}getRange(t){const e=t.split(",");return e.length===3?[e[1],e[2]]:!1}getCharecterOffsetComponent(t){return t.split(":")[1]||""}joinSteps(t){return t?t.map(function(e){let i="";return e.type==="element"&&(i+=(e.index+1)*2),e.type==="text"&&(i+=1+2*e.index),e.id&&(i+="["+e.id+"]"),i}).join("/"):""}segmentString(t){let e="/";return e+=this.joinSteps(t.steps),t.terminal&&t.terminal.offset!=null&&(e+=":"+t.terminal.offset),t.terminal&&t.terminal.assertion!=null&&(e+="["+t.terminal.assertion+"]"),e}toString(){let 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+=")",t}compare(t,e){let i,n,s,r;if(typeof t=="string"&&(t=new et(t)),typeof e=="string"&&(e=new et(e)),t.spinePos>e.spinePos)return 1;if(t.spinePos<e.spinePos)return-1;t.range?(i=t.path.steps.concat(t.start.steps),s=t.start.terminal):(i=t.path.steps,s=t.path.terminal),e.range?(n=e.path.steps.concat(e.start.steps),r=e.start.terminal):(n=e.path.steps,r=e.path.terminal);for(let o=0;o<i.length;o++){if(!i[o])return-1;if(!n[o]||i[o].index>n[o].index)return 1;if(i[o].index<n[o].index)return-1}return i.length<n.length?-1:s.offset>r.offset?1:s.offset<r.offset?-1:0}step(t){const e=t.nodeType===At?"text":"element";return{id:t.id,tagName:t.tagName,type:e,index:this.position(t)}}filteredStep(t,e){const i=this.filter(t,e);if(!i)return;const n=i.nodeType===At?"text":"element";return{id:i.id,tagName:i.tagName,type:n,index:this.filteredPosition(i,e)}}pathTo(t,e,i){const n={steps:[],terminal:{offset:null,assertion:null}};let s=t,r;for(;s&&s.parentNode&&s.parentNode.nodeType!=Hn;)i?r=this.filteredStep(s,i):r=this.step(s),r&&n.steps.unshift(r),s=s.parentNode;return e!=null&&e>=0&&(n.terminal.offset=e,n.steps[n.steps.length-1].type!="text"&&n.steps.push({type:"text",index:0,id:null,tagName:""})),n}equalStep(t,e){return!t||!e?!1:t.index===e.index&&t.id===e.id&&t.type===e.type}fromRange(t,e,i){const n={range:!1,base:{},path:{},start:null,end:null},s=t.startContainer,r=t.endContainer;let o=t.startOffset,l=t.endOffset,f=!1;if(i&&(f=s.ownerDocument.querySelector("."+i)!=null),typeof e=="string"?(n.base=this.parseComponent(e),n.spinePos=n.base.steps[1].index):typeof e=="object"&&(n.base=e),t.collapsed)f&&(o=this.patchOffset(s,o,i)),n.path=this.pathTo(s,o,i);else{n.range=!0,f&&(o=this.patchOffset(s,o,i)),n.start=this.pathTo(s,o,i),f&&(l=this.patchOffset(r,l,i)),n.end=this.pathTo(r,l,i),n.path={steps:[],terminal:null};const m=n.start.steps.length;let b;for(b=0;b<m&&this.equalStep(n.start.steps[b],n.end.steps[b]);b++)b===m-1?n.start.terminal===n.end.terminal&&(n.path.steps.push(n.start.steps[b]),n.range=!1):n.path.steps.push(n.start.steps[b]);n.start.steps=n.start.steps.slice(n.path.steps.length),n.end.steps=n.end.steps.slice(n.path.steps.length)}return n}fromNode(t,e,i){const n={range:!1,base:{},path:{},start:null,end:null};return typeof e=="string"?(n.base=this.parseComponent(e),n.spinePos=n.base.steps[1].index):typeof e=="object"&&(n.base=e),n.path=this.pathTo(t,null,i),n}filter(t,e){let i,n,s,r,o,l=!1;return t.nodeType===At?(l=!0,s=t.parentNode,i=t.parentNode.classList.contains(e)):(l=!1,i=t.classList.contains(e)),i&&l?(r=s.previousSibling,o=s.nextSibling,r&&r.nodeType===At?n=r:o&&o.nodeType===At&&(n=o),n||t):i&&!l?!1:t}patchOffset(t,e,i){if(t.nodeType!=At)throw new Error("Anchor must be a text node");let n=t,s=e;for(t.parentNode.classList.contains(i)&&(n=t.parentNode);n.previousSibling;){if(n.previousSibling.nodeType===ue)if(n.previousSibling.classList.contains(i))s+=(n.previousSibling.textContent??"").length;else break;else s+=(n.previousSibling.textContent??"").length;n=n.previousSibling}return s}normalizedMap(t,e,i){const n={};let s=-1,r;const o=t.length;let l,f;for(r=0;r<o;r++)l=t[r].nodeType,l===ue&&t[r].classList.contains(i)&&(l=At),r>0&&l===At&&f===At?n[r]=s:e===l&&(s=s+1,n[r]=s),f=l;return n}position(t){let e,i;return t.nodeType===ue?(e=t.parentNode.children,e||(e=hi(t.parentNode)),i=Array.prototype.indexOf.call(e,t)):(e=this.textNodes(t.parentNode),i=e.indexOf(t)),i}filteredPosition(t,e){let i,n;t.nodeType===ue?(i=t.parentNode.children,n=this.normalizedMap(i,ue,e)):(i=t.parentNode.childNodes,t.parentNode.classList.contains(e)&&(t=t.parentNode,i=t.parentNode.childNodes),n=this.normalizedMap(i,At,e));const s=Array.prototype.indexOf.call(i,t);return n[s]}stepsToXpath(t){const e=[".","*"];return t.forEach(function(i){const n=i.index+1;i.id?e.push("*[position()="+n+" and @id='"+i.id+"']"):i.type==="text"?e.push("text()["+n+"]"):e.push("*["+n+"]")}),e.join("/")}stepsToQuerySelector(t){const e=["html"];return t.forEach(function(i){const n=i.index+1;i.id?e.push("#"+i.id):i.type==="text"||e.push("*:nth-child("+n+")")}),e.join(">")}textNodes(t,e){return Array.prototype.slice.call(t.childNodes).filter(function(i){return i.nodeType===At?!0:!!(e&&i.classList.contains(e))})}walkToNode(t,e,i){const n=e||document;let s=n.documentElement,r,o;const l=t.length;let f;for(f=0;f<l&&(o=t[f],o.type==="element"?o.id?s=n.getElementById(o.id):(r=s.children||hi(s),s=r[o.index]):o.type==="text"&&(s=this.textNodes(s,i)[o.index]),!!s);f++);return s}findNode(t,e,i){const n=e||document;let s,r;return!i&&typeof n.evaluate<"u"?(r=this.stepsToXpath(t),s=n.evaluate(r,n,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue??void 0):i?s=this.walkToNode(t,n,i):s=this.walkToNode(t,n),s}fixMiss(t,e,i,n){let s=this.findNode(t.slice(0,-1),i,n);const r=s.childNodes,o=this.normalizedMap(r,At,n);let l,f;const m=t[t.length-1].index;for(const b in o)if(o.hasOwnProperty(b)&&o[b]===m)if(l=r[b],f=(l.textContent??"").length,e>f)e=e-f;else{l.nodeType===ue?s=l.childNodes[0]:s=l;break}return{container:s,offset:e}}toRange(t,e){const i=t||document;let n,s,r,o,l;const f=this;let m,b;const E=e?i.querySelector("."+e)!=null:!1;let N;if(typeof i.createRange<"u"?n=i.createRange():n=new Xi,f.range?(s=f.start,m=f.path.steps.concat(s.steps),o=this.findNode(m,i,E?e:void 0),r=f.end,b=f.path.steps.concat(r.steps),l=this.findNode(b,i,E?e:void 0)):(s=f.path,m=f.path.steps,o=this.findNode(f.path.steps,i,E?e:void 0)),o)try{s.terminal.offset!=null?n.setStart(o,s.terminal.offset):n.setStart(o,0)}catch{N=this.fixMiss(m,s.terminal.offset,i,E?e:void 0),n.setStart(N.container,N.offset)}else return console.log("No startContainer found for",this.toString()),null;if(l)try{r.terminal.offset!=null?n.setEnd(l,r.terminal.offset):n.setEnd(l,0)}catch{N=this.fixMiss(b,f.end.terminal.offset,i,E?e:void 0),n.setEnd(N.container,N.offset)}return n}isCfiString(t){return typeof t=="string"&&t.indexOf("epubcfi(")===0&&t[t.length-1]===")"}generateChapterComponent(t,e,i){const n=parseInt(e);let r="/"+(t+1)*2+"/";return r+=(n+1)*2,i&&(r+="["+i+"]"),r}collapse(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))}}class Mt{constructor(t){this.context=t||this,this.hooks=[]}register(...t){for(let e=0;e<arguments.length;++e)if(typeof arguments[e]=="function")this.hooks.push(arguments[e]);else for(let i=0;i<arguments[e].length;++i)this.hooks.push(arguments[e][i])}deregister(t){let e;for(let i=0;i<this.hooks.length;i++)if(e=this.hooks[i],e===t){this.hooks.splice(i,1);break}}trigger(...t){const e=arguments,i=this.context,n=[];return this.hooks.forEach(function(s){let r;try{r=s.apply(i,e)}catch(o){console.log(o)}r&&typeof r.then=="function"&&n.push(r)}),Promise.all(n)}list(){return this.hooks}clear(){return this.hooks=[]}}function Yi(h,t){let e,i=t.url;const n=i.indexOf("://")>-1;if(!h)return;const s=lt(h,"head");e=lt(s,"base"),e||(e=h.createElement("base"),s.insertBefore(e,s.firstChild)),!n&&window&&window.location&&(i=window.location.origin+i),e.setAttribute("href",i)}function Xn(h,t){let e;const i=t.canonical;if(!h)return;const n=lt(h,"head");e=lt(n,"link[rel='canonical']"),e?e.setAttribute("href",i):(e=h.createElement("link"),e.setAttribute("rel","canonical"),e.setAttribute("href",i),n.appendChild(e))}function Yn(h,t){let e;const i=t.idref;if(!h)return;const n=lt(h,"head");e=lt(n,"link[property='dc.identifier']"),e?e.setAttribute("content",i):(e=h.createElement("meta"),e.setAttribute("name","dc.identifier"),e.setAttribute("content",i),n.appendChild(e))}function $n(h,t){const e=h.querySelectorAll("a[href]");if(!e.length)return;const i=lt(h.ownerDocument,"base"),n=i?i.getAttribute("href")??void 0:void 0,s=(function(r){const o=r.getAttribute("href")??"";if(o.indexOf("mailto:")===0)return;if(o.indexOf("://")>-1)r.setAttribute("target","_blank");else{let f;try{f=new Pt(o,n)}catch{}r.onclick=function(){return f&&f.hash?t(f.Path.path+f.hash):t(f?f.Path.path:o),!1}}}).bind(this);for(let r=0;r<e.length;r++)s(e[r])}function Ci(h,t,e){return t.forEach(function(i,n){i&&e[n]&&(i=i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),h=h.replace(new RegExp(i,"g"),e[n]))}),h}function Ce(h,t,e,i){const n=typeof window<"u"?window.URL:!1,s=n?"blob":"arraybuffer",r=new st,o=new XMLHttpRequest,l=XMLHttpRequest.prototype;let f;"overrideMimeType"in l||Object.defineProperty(l,"overrideMimeType",{value:function(){}}),e&&(o.withCredentials=!0),o.onreadystatechange=b,o.onerror=m,o.open("GET",h,!0);for(f in i)o.setRequestHeader(f,i[f]);t=="json"&&o.setRequestHeader("Accept","application/json"),t||(t=new Zt(h).extension),t=="blob"&&(o.responseType=s),Ne(t)&&o.overrideMimeType("text/xml"),t=="binary"&&(o.responseType="arraybuffer"),o.send();function m(E){r.reject(E)}function b(){if(this.readyState===XMLHttpRequest.DONE){let E=!1;if((this.responseType===""||this.responseType==="document")&&(E=this.responseXML),this.status===200||this.status===0||E){let N;if(!this.response&&!E)return r.reject({status:this.status,message:"Empty Response",stack:new Error().stack}),r.promise;if(this.status===403)return r.reject({status:this.status,response:this.response,message:"Forbidden",stack:new Error().stack}),r.promise;E?N=this.responseXML:Ne(t)?N=Ut(this.response,"text/xml"):t=="xhtml"?N=Ut(this.response,"application/xhtml+xml"):t=="html"||t=="htm"?N=Ut(this.response,"text/html"):t=="json"?N=JSON.parse(this.response):t=="blob"?n?N=this.response:N=new Blob([this.response]):N=this.response,r.resolve(N)}else r.reject({status:this.status,message:this.response,stack:new Error().stack})}}return r.promise}class Gn{constructor(t,e){this.idref=t.idref,this.linear=t.linear==="yes",this.properties=t.properties,this.index=t.index,this.href=t.href,this.url=t.url,this.canonical=t.canonical,this.next=t.next,this.prev=t.prev,this.cfiBase=t.cfiBase,e?this.hooks=e:(this.hooks={},this.hooks.serialize=new Mt(this),this.hooks.content=new Mt(this)),this.document=void 0,this.contents=void 0,this.output=void 0}load(t){const e=t||this.request||Ce,i=new st,n=i.promise;return this.contents?i.resolve(this.contents):e(this.url).then((function(s){return this.document=s,this.contents=s.documentElement,this.hooks.content.trigger(this.document,this)}).bind(this)).then((function(){i.resolve(this.contents)}).bind(this)).catch(function(s){i.reject(s)}),n}base(){return Yi(this.document,this)}render(t){const e=new st,i=e.promise;return this.output,this.load(t).then((function(n){const r=(typeof navigator<"u"&&navigator.userAgent||"").indexOf("Trident")>=0;let o;typeof XMLSerializer>"u"||r?o=Pi.DOMParser:o=XMLSerializer;const l=new o;return this.output=l.serializeToString(n),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(n){e.reject(n)}),i}find(t){const e=this,i=[],n=t.toLowerCase(),s=function(r){const o=r.textContent.toLowerCase();let l,f,m,b=-1,E;const N=150;for(;m!=-1;)m=o.indexOf(n,b+1),m!=-1&&(l=e.document.createRange(),l.setStart(r,m),l.setEnd(r,m+n.length),f=e.cfiFromRange(l),r.textContent.length<N?E=r.textContent:(E=r.textContent.substring(m-N/2,m+N/2),E="..."+E+"..."),i.push({cfi:f,excerpt:E})),b=m};return qe(e.document,function(r){s(r)}),i}search(t,e=5){if(typeof document.createTreeWalker>"u")return this.find(t);const i=[],n=150,s=this,r=t.toLowerCase(),o=function(b){const W=b.reduce((T,D)=>T+(D.textContent??""),"").toLowerCase().indexOf(r);if(W!=-1){const D=W+r.length;let q=0,U=0;if(W<b[0].length){for(;q<b.length-1&&(U+=b[q].length,!(D<=U));)q+=1;const $=b[0],X=b[q],R=s.document.createRange();R.setStart($,W);const z=b.slice(0,q).reduce((_,I)=>_+(I.textContent??"").length,0);R.setEnd(X,z>D?D:D-z);const P=s.cfiFromRange(R);let Y=b.slice(0,q+1).reduce((_,I)=>_+(I.textContent??""),"");Y.length>n&&(Y=Y.substring(W-n/2,W+n/2),Y="..."+Y+"..."),i.push({cfi:P,excerpt:Y})}}},l=document.createTreeWalker(s.document,NodeFilter.SHOW_TEXT,null);let f,m=[];for(;f=l.nextNode();)m.push(f),m.length==e&&(o(m.slice(0,e)),m=m.slice(1,e));return m.length>0&&o(m),i}reconcileLayoutSettings(t){const e={layout:t.layout,spread:t.spread,orientation:t.orientation};return this.properties.forEach(function(i){const n=i.replace("rendition:",""),s=n.indexOf("-");let r,o;s!=-1&&(r=n.slice(0,s),o=n.slice(s+1),e[r]=o)}),e}cfiFromRange(t){return new et(t,this.cfiBase).toString()}cfiFromElement(t){return new et(t,this.cfiBase).toString()}unload(){this.document=void 0,this.contents=void 0,this.output=void 0}destroy(){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}}class Kn{constructor(){this.spineItems=[],this.spineByHref={},this.spineById={},this.hooks={},this.hooks.serialize=new Mt,this.hooks.content=new Mt,this.hooks.content.register(Yi),this.hooks.content.register(Xn),this.hooks.content.register(Yn),this.epubcfi=new et,this.loaded=!1,this.items=[],this.manifest={},this.spineNodeIndex=0,this.baseUrl="",this.length=0}unpack(t,e,i){this.items=t.spine,this.manifest=t.manifest,this.spineNodeIndex=t.spineNodeIndex,this.baseUrl=t.baseUrl||t.basePath||"",this.length=this.items.length,this.items.forEach((n,s)=>{const r=this.manifest[n.idref];n.index=s,n.cfiBase=this.epubcfi.generateChapterComponent(this.spineNodeIndex,n.index,n.id),n.href&&(n.url=e(n.href,!0),n.canonical=i(n.href)),r&&(n.href=r.href,n.url=e(n.href,!0),n.canonical=i(n.href),r.properties.length&&n.properties.push.apply(n.properties,r.properties)),n.linear==="yes"?(n.prev=(function(){let l=n.index;for(;l>0;){const f=this.get(l-1);if(f&&f.linear)return f;l-=1}}).bind(this),n.next=(function(){let l=n.index;for(;l<this.spineItems.length-1;){const f=this.get(l+1);if(f&&f.linear)return f;l+=1}}).bind(this)):(n.prev=function(){},n.next=function(){});const o=new Gn(n,this.hooks);this.append(o)}),this.loaded=!0}get(t){let e=0;if(typeof t>"u")for(;e<this.spineItems.length;){const i=this.spineItems[e];if(i&&i.linear)break;e+=1}else this.epubcfi.isCfiString(t)?e=new et(t).spinePos:typeof t=="number"||isNaN(Number(t))===!1?e=Number(t):typeof t=="string"&&t.indexOf("#")===0?e=this.spineById[t.substring(1)]:typeof t=="string"&&(t=t.split("#")[0],e=this.spineByHref[t]||this.spineByHref[encodeURI(t)]);return this.spineItems[e]||null}append(t){const e=this.spineItems.length;return t.index=e,this.spineItems.push(t),this.spineByHref[decodeURI(t.href)]=e,this.spineByHref[encodeURI(t.href)]=e,this.spineByHref[t.href]=e,this.spineById[t.idref]=e,e}prepend(t){return this.spineByHref[t.href]=0,this.spineById[t.idref]=0,this.spineItems.forEach(function(e,i){e.index=i}),0}remove(t){const e=this.spineItems.indexOf(t);if(e>-1)return delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)}each(...t){return this.spineItems.forEach.apply(this.spineItems,t)}first(){let t=0;do{const e=this.get(t);if(e&&e.linear)return e;t+=1}while(t<this.spineItems.length)}last(){let t=this.spineItems.length-1;do{const e=this.get(t);if(e&&e.linear)return e;t-=1}while(t>=0)}destroy(){this.each(t=>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}}class gi{constructor(t){this._q=[],this.context=t,this.tick=di,this.running=!1,this.paused=!1}enqueue(...t){let e,i,n;const s=[].shift.call(arguments),r=arguments;if(!s)throw new Error("No Task Provided");return typeof s=="function"?(e=new st,i=e.promise,n={task:s,args:r,deferred:e,promise:i}):n={promise:s},this._q.push(n),this.paused==!1&&!this.running&&this.run(),n.promise}dequeue(){let t,e,i;if(this._q.length&&!this.paused){if(t=this._q.shift(),e=t.task,e)return i=e.apply(this.context,t.args),i&&typeof i.then=="function"?i.then((function(){t.deferred.resolve.apply(this.context,arguments)}).bind(this),(function(){t.deferred.reject.apply(this.context,arguments)}).bind(this)):(t.deferred.resolve.apply(this.context,i),t.promise);if(t.promise)return t.promise}else return t=new st,t.resolve(),t.promise}dump(){for(;this._q.length;)this.dequeue()}run(){return this.running||(this.running=!0,this.defered=new st),this.tick.call(window,()=>{this._q.length?this.dequeue().then((function(){this.run()}).bind(this)):(this.defered.resolve(),this.running=void 0)}),this.paused==!0&&(this.paused=!1),this.defered.promise}flush(){if(this.running)return this.running;if(this._q.length)return this.running=this.dequeue().then((function(){return this.running=void 0,this.flush()}).bind(this)),this.running}clear(){this._q=[]}length(){return this._q.length}pause(){this.paused=!0}stop(){this._q=[],this.running=!1,this.paused=!0}}const Ye="0.3",Me=["keydown","keyup","keypressed","mouseup","mousedown","mousemove","click","touchend","touchstart","touchmove"],M={BOOK:{OPEN_FAILED:"openFailed"},CONTENTS:{EXPAND:"expand",RESIZE:"resize",SELECTED:"selected",SELECTED_RANGE:"selectedRange",LINK_CLICKED:"linkClicked"},LOCATIONS:{CHANGED:"changed"},MANAGERS:{RESIZE:"resize",RESIZED:"resized",ORIENTATION_CHANGE:"orientationchange",ADDED:"added",SCROLL:"scroll",SCROLLED:"scrolled",REMOVED:"removed"},VIEWS:{AXIS:"axis",WRITING_MODE:"writingMode",LOAD_ERROR:"loaderror",RENDERED:"rendered",RESIZED:"resized",DISPLAYED:"displayed",SHOWN:"shown",HIDDEN:"hidden",MARK_CLICKED:"markClicked"},RENDITION:{STARTED:"started",ATTACHED:"attached",DISPLAYED:"displayed",DISPLAY_ERROR:"displayerror",RENDERED:"rendered",REMOVED:"removed",RESIZED:"resized",ORIENTATION_CHANGE:"orientationchange",LOCATION_CHANGED:"locationChanged",RELOCATED:"relocated",MARK_CLICKED:"markClicked",SELECTED:"selected",LAYOUT:"layout"},LAYOUT:{UPDATED:"updated"},ANNOTATION:{ATTACH:"attach",DETACH:"detach"}};class $i{constructor(t,e,i){this.spine=t,this.request=e,this.pause=i||100,this.q=new gi(this),this.epubcfi=new et,this._locations=[],this._locationsWords=[],this.total=0,this.break=150,this._current=0,this._wordCounter=0,this._currentCfi="",this.processingTimeout=void 0}generate(t){return t&&(this.break=t),this.q.pause(),this.spine.each((function(e){e.linear&&this.q.enqueue(this.process.bind(this),e)}).bind(this)),this.q.run().then((function(){return this.total=this._locations.length-1,this._currentCfi&&(this.currentLocation=this._currentCfi),this._locations}).bind(this))}createRange(){return{startContainer:void 0,startOffset:void 0,endContainer:void 0,endOffset:void 0}}process(t){return t.load(this.request).then((function(e){const i=new st,n=this.parse(e,t.cfiBase);return this._locations=this._locations.concat(n),t.unload(),this.processingTimeout=setTimeout(()=>i.resolve(n),this.pause),i.promise}).bind(this))}parse(t,e,i){const n=[];let s;const r=t.ownerDocument,o=lt(r,"body");let l=0,f;const m=i||this.break;if(qe(o,(function(E){const N=E.length;let W,T=0;if((E.textContent??"").trim().length===0)return!1;for(l==0&&(s=this.createRange(),s.startContainer=E,s.startOffset=0),W=m-l,W>N&&(l+=N,T=N);T<N;)if(W=m-l,l===0&&(T+=1,s=this.createRange(),s.startContainer=E,s.startOffset=T),T+W>=N)l+=N-T,T=N;else{T+=W,s.endContainer=E,s.endOffset=T;const D=new et(s,e).toString();n.push(D),l=0}f=E}).bind(this)),s&&s.startContainer&&f){s.endContainer=f,s.endOffset=f.length;const E=new et(s,e).toString();n.push(E),l=0}return n}generateFromWords(t,e,i){const n=t?new et(t):void 0;return this.q.pause(),this._locationsWords=[],this._wordCounter=0,this.spine.each((function(s){s.linear&&(n?s.index>=n.spinePos&&this.q.enqueue(this.processWords.bind(this),s,e,n,i):this.q.enqueue(this.processWords.bind(this),s,e,n,i))}).bind(this)),this.q.run().then((function(){return this._currentCfi&&(this.currentLocation=this._currentCfi),this._locationsWords}).bind(this))}processWords(t,e,i,n){return n&&this._locationsWords.length>=n?Promise.resolve():t.load(this.request).then((function(s){const r=new st,o=this.parseWords(s,t,e,i),l=n-this._locationsWords.length;return this._locationsWords=this._locationsWords.concat(o.length>=n?o.slice(0,l):o),t.unload(),this.processingTimeout=setTimeout(()=>r.resolve(o),this.pause),r.promise}).bind(this))}countWords(t){return t=t.replace(/(^\s*)|(\s*$)/gi,""),t=t.replace(/[ ]{2,}/gi," "),t=t.replace(/\n /,`
3
+ `),t.split(" ").length}parseWords(t,e,i,n){const s=e.cfiBase,r=[],o=t.ownerDocument,l=lt(o,"body"),f=i;let m=n?n.spinePos!==e.index:!0,b;return n&&e.index===n.spinePos&&(b=n.findNode(n.range?n.path.steps.concat(n.start.steps):n.path.steps,t.ownerDocument)),qe(l,(function(N){if(!m)if(N===b)m=!0;else return!1;if((N.textContent??"").length<10&&(N.textContent??"").trim().length===0)return!1;const W=this.countWords(N.textContent??"");let T,D=0;if(W===0)return!1;for(T=f-this._wordCounter,T>W&&(this._wordCounter+=W,D=W);D<W;)if(T=f-this._wordCounter,D+T>=W)this._wordCounter+=W-D,D=W;else{D+=T;const q=new et(N,s);r.push({cfi:q.toString(),wordCount:this._wordCounter}),this._wordCounter=0}}).bind(this)),r}locationFromCfi(t){if(et.prototype.isCfiString(t)&&(t=new et(t)),this._locations.length===0)return-1;const e=me(t,this._locations,this.epubcfi.compare);return e>this.total?this.total:e}percentageFromCfi(t){if(this._locations.length===0)return null;const e=this.locationFromCfi(t);return this.percentageFromLocation(e)}percentageFromLocation(t){return!t||!this.total?0:t/this.total}cfiFromLocation(t){let e=-1;return typeof t!="number"&&(t=parseInt(t)),t>=0&&t<this._locations.length&&(e=this._locations[t]),e}cfiFromPercentage(t){if(t>1&&console.warn("Normalize cfiFromPercentage value to between 0 - 1"),t>=1){const i=new et(this._locations[this.total]);return i.collapse(),i.toString()}const e=Math.ceil(this.total*t);return this.cfiFromLocation(e)}load(t){return typeof t=="string"?this._locations=JSON.parse(t):this._locations=t,this.total=this._locations.length-1,this._locations}save(){return JSON.stringify(this._locations)}getCurrent(){return this._current}setCurrent(t){let e;if(typeof t=="string")this._currentCfi=t;else if(typeof t=="number")this._current=t;else return;this._locations.length!==0&&(typeof t=="string"?(e=this.locationFromCfi(t),this._current=e):e=t,this.emit(M.LOCATIONS.CHANGED,{percentage:this.percentageFromLocation(e)}))}get currentLocation(){return this._current}set currentLocation(t){this.setCurrent(t)}length(){return this._locations.length}destroy(){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)}}Wt($i.prototype);class Zn{constructor(t){this.packagePath="",this.directory="",this.encoding="",t&&this.parse(t)}parse(t){if(!t)throw new Error("Container File Not Found");const e=lt(t,"rootfile");if(!e)throw new Error("No RootFile Found");this.packagePath=e.getAttribute("full-path")??"",this.directory=ee.dirname(this.packagePath),this.encoding=t.xmlEncoding}destroy(){this.packagePath=void 0,this.directory=void 0,this.encoding=void 0}}class Ri{constructor(t){this.manifest={},this.navPath="",this.ncxPath="",this.coverPath="",this.spineNodeIndex=0,this.spine=[],this.metadata={},t&&this.parse(t)}parse(t){if(!t)throw new Error("Package File Not Found");const e=lt(t,"metadata");if(!e)throw new Error("No Metadata Found");const i=lt(t,"manifest");if(!i)throw new Error("No Manifest Found");const n=lt(t,"spine");if(!n)throw new Error("No Spine Found");return this.manifest=this.parseManifest(i),this.navPath=this.findNavPath(i),this.ncxPath=this.findNcxPath(i,n),this.coverPath=this.findCoverPath(t),this.spineNodeIndex=Wi(n),this.spine=this.parseSpine(n,this.manifest),this.uniqueIdentifier=this.findUniqueIdentifier(t),this.metadata=this.parseMetadata(e),this.metadata.direction=n.getAttribute("page-progression-direction")??"",{metadata:this.metadata,spine:this.spine,manifest:this.manifest,navPath:this.navPath,ncxPath:this.ncxPath,coverPath:this.coverPath,spineNodeIndex:this.spineNodeIndex}}parseMetadata(t){const e={};return e.title=this.getElementText(t,"title"),e.creator=this.getElementText(t,"creator"),e.description=this.getElementText(t,"description"),e.pubdate=this.getElementText(t,"date"),e.publisher=this.getElementText(t,"publisher"),e.identifier=this.getElementText(t,"identifier"),e.language=this.getElementText(t,"language"),e.rights=this.getElementText(t,"rights"),e.modified_date=this.getPropertyText(t,"dcterms:modified"),e.layout=this.getPropertyText(t,"rendition:layout"),e.orientation=this.getPropertyText(t,"rendition:orientation"),e.flow=this.getPropertyText(t,"rendition:flow"),e.viewport=this.getPropertyText(t,"rendition:viewport"),e.media_active_class=this.getPropertyText(t,"media:active-class"),e.spread=this.getPropertyText(t,"rendition:spread"),e}parseManifest(t){const e={},i=Kt(t,"item");return Array.prototype.slice.call(i).forEach(function(s){const r=s.getAttribute("id")??"",o=s.getAttribute("href")||"",l=s.getAttribute("media-type")||"",f=s.getAttribute("media-overlay")||"",m=s.getAttribute("properties")||"";e[r]={href:o,type:l,overlay:f,properties:m.length?m.split(" "):[]}}),e}parseSpine(t,e){const i=[],n=Kt(t,"itemref");return Array.prototype.slice.call(n).forEach(function(r,o){const l=r.getAttribute("idref"),f=r.getAttribute("properties")||"",m=f.length?f.split(" "):[],b={id:r.getAttribute("id")??void 0,idref:l,linear:r.getAttribute("linear")||"yes",properties:m,index:o};i.push(b)}),i}findUniqueIdentifier(t){const e=t.documentElement.getAttribute("unique-identifier");if(!e)return"";const i=t.getElementById(e);return i&&i.localName==="identifier"&&i.namespaceURI==="http://purl.org/dc/elements/1.1/"&&i.childNodes.length>0?(i.childNodes[0].nodeValue??"").trim():""}findNavPath(t){const e=fe(t,"item",{properties:"nav"});return e&&e.getAttribute("href")||""}findNcxPath(t,e){let i=fe(t,"item",{"media-type":"application/x-dtbncx+xml"}),n;return i||(n=e.getAttribute("toc"),n&&(i=t.querySelector(`#${n}`)??void 0)),i&&i.getAttribute("href")||""}findCoverPath(t){const e=lt(t,"package");e==null||e.getAttribute("version");const i=fe(t,"item",{properties:"cover-image"});if(i)return i.getAttribute("href")??"";const n=fe(t,"meta",{name:"cover"});if(n){const s=n.getAttribute("content"),r=t.getElementById(s);return r?r.getAttribute("href")??"":""}else return""}getElementText(t,e){const i=t.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",e);if(!i||i.length===0)return"";const n=i[0];return n.childNodes.length?n.childNodes[0].nodeValue??"":""}getPropertyText(t,e){const i=fe(t,"meta",{property:e});return i&&i.childNodes.length?i.childNodes[0].nodeValue??"":""}load(t){this.metadata=t.metadata;const e=t.readingOrder||t.spine;return this.spine=e.map((i,n)=>(i.index=n,i.linear=i.linear||"yes",i)),t.resources.forEach((i,n)=>{this.manifest[n]=i,i.rel&&i.rel[0]==="cover"&&(this.coverPath=i.href)}),this.spineNodeIndex=0,this.toc=t.toc.map(i=>(i.label=i.title||i.label,i)),{metadata:this.metadata,spine:this.spine,manifest:this.manifest,navPath:this.navPath,ncxPath:this.ncxPath,coverPath:this.coverPath,spineNodeIndex:this.spineNodeIndex,toc:this.toc}}destroy(){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}}class ii{constructor(t){this.toc=[],this.tocByHref={},this.tocById={},this.landmarks=[],this.landmarksByType={},this.length=0,t&&this.parse(t)}parse(t){const e=t.nodeType;let i,n;e&&(i=lt(t,"html"),n=lt(t,"ncx")),e?i?(this.toc=this.parseNav(t),this.landmarks=this.parseLandmarks(t)):n&&(this.toc=this.parseNcx(t)):this.toc=this.load(t),this.length=0,this.unpack(this.toc)}unpack(t){let e;for(let i=0;i<t.length;i++)e=t[i],e.href&&(this.tocByHref[e.href]=i),e.id&&(this.tocById[e.id]=i),this.length++,e.subitems&&e.subitems.length&&this.unpack(e.subitems)}get(t){let e;return t?(t.indexOf("#")===0?e=this.tocById[t.substring(1)]:t in this.tocByHref&&(e=this.tocByHref[t]),this.getByIndex(t,e,this.toc)):this.toc}getByIndex(t,e,i){if(i.length===0)return;const n=e!==void 0?i[e]:void 0;if(n&&(t===n.id||t===n.href))return n;{let s;for(let r=0;r<i.length&&(s=this.getByIndex(t,e,i[r].subitems??[]),!s);++r);return s}}landmark(t){if(!t)return this.landmarks;const e=this.landmarksByType[t];return this.landmarks[e]}parseNav(t){const e=Fe(t,"nav","toc");let i=[];if(!e)return i;const n=pe(e,"ol",!0);return n&&(i=this.parseNavList(n)),i}parseNavList(t,e){const i=[];if(!t||!t.children)return i;for(let n=0;n<t.children.length;n++){const s=this.navItem(t.children[n],e);s&&i.push(s)}return i}navItem(t,e){let i=t.getAttribute("id")||void 0;const n=pe(t,"a",!0)||pe(t,"span",!0);if(!n)return;const s=n.getAttribute("href")||"";i||(i=s);const r=n.textContent||"";let o=[];const l=pe(t,"ol",!0);return l&&(o=this.parseNavList(l,i)),{id:i,href:s,label:r,subitems:o,parent:e}}parseLandmarks(t){const e=Fe(t,"nav","landmarks"),i=e?Array.from(Kt(e,"li")):[],n=i.length;let s;const r=[];let o;if(!i||n===0)return r;for(s=0;s<n;++s)o=this.landmarkItem(i[s]),o&&(r.push(o),this.landmarksByType[o.type]=s);return r}landmarkItem(t){const e=pe(t,"a",!0);if(!e)return;const i=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||void 0,n=e.getAttribute("href")||"",s=e.textContent||"";return{href:n,label:s,type:i}}parseNcx(t){const e=Kt(t,"navPoint"),i=e.length;let n;const s={},r=[];let o,l;if(!e||i===0)return r;for(n=0;n<i;++n)o=this.ncxItem(e[n]),s[o.id]=o,o.parent?(l=s[o.parent],l.subitems.push(o)):r.push(o);return r}ncxItem(t){const e=t.getAttribute("id")||"",i=lt(t,"content"),n=i?i.getAttribute("src")??"":"",s=lt(t,"navLabel"),r=s!=null&&s.textContent?s.textContent:"",o=[],l=t.parentNode;let f;return l&&(l.nodeName==="navPoint"||l.nodeName.split(":").slice(-1)[0]==="navPoint")&&(f=l.getAttribute("id")??void 0),{id:e,href:n,label:r,subitems:o,parent:f}}load(t){return t.map(e=>(e.label=e.title,e.subitems=e.children?this.load(e.children):[],e))}forEach(t){return this.toc.forEach(t)}}const Te={application:{ecmascript:["es","ecma"],javascript:"js",ogg:"ogx",pdf:"pdf",postscript:["ps","ai","eps","epsi","epsf","eps2","eps3"],"rdf+xml":"rdf",smil:["smi","smil"],"xhtml+xml":["xhtml","xht"],xml:["xml","xsl","xsd","opf","ncx"],zip:"zip","x-httpd-eruby":"rhtml","x-latex":"latex","x-maker":["frm","maker","frame","fm","fb","book","fbdoc"],"x-object":"o","x-shockwave-flash":["swf","swfl"],"x-silverlight":"scr","epub+zip":"epub","font-tdpfr":"pfr","inkml+xml":["ink","inkml"],json:"json","jsonml+json":"jsonml","mathml+xml":"mathml","metalink+xml":"metalink",mp4:"mp4s","omdoc+xml":"omdoc",oxps:"oxps","vnd.amazon.ebook":"azw",widget:"wgt","x-dtbook+xml":"dtb","x-dtbresource+xml":"res","x-font-bdf":"bdf","x-font-ghostscript":"gsf","x-font-linux-psf":"psf","x-font-otf":"otf","x-font-pcf":"pcf","x-font-snf":"snf","x-font-ttf":["ttf","ttc"],"x-font-type1":["pfa","pfb","pfm","afm"],"x-font-woff":"woff","x-mobipocket-ebook":["prc","mobi"],"x-mspublisher":"pub","x-nzb":"nzb","x-tgif":"obj","xaml+xml":"xaml","xml-dtd":"dtd","xproc+xml":"xpl","xslt+xml":"xslt","internet-property-stream":"acx","x-compress":"z","x-compressed":"tgz","x-gzip":"gz"},audio:{flac:"flac",midi:["mid","midi","kar","rmi"],mpeg:["mpga","mpega","mp2","mp3","m4a","mp2a","m2a","m3a"],mpegurl:"m3u",ogg:["oga","ogg","spx"],"x-aiff":["aif","aiff","aifc"],"x-ms-wma":"wma","x-wav":"wav",adpcm:"adp",mp4:"mp4a",webm:"weba","x-aac":"aac","x-caf":"caf","x-matroska":"mka","x-pn-realaudio-plugin":"rmp",xm:"xm",mid:["mid","rmi"]},image:{gif:"gif",ief:"ief",jpeg:["jpeg","jpg","jpe"],pcx:"pcx",png:"png","svg+xml":["svg","svgz"],tiff:["tiff","tif"],"x-icon":"ico",bmp:"bmp",webp:"webp","x-pict":["pic","pct"],"x-tga":"tga","cis-cod":"cod"},text:{"cache-manifest":["manifest","appcache"],css:"css",csv:"csv",html:["html","htm","shtml","stm"],mathml:"mml",plain:["txt","text","brf","conf","def","list","log","in","bas"],richtext:"rtx","tab-separated-values":"tsv","x-bibtex":"bib"},video:{mpeg:["mpeg","mpg","mpe","m1v","m2v","mp2","mpa","mpv2"],mp4:["mp4","mp4v","mpg4"],quicktime:["qt","mov"],ogg:"ogv","vnd.mpegurl":["mxu","m4u"],"x-flv":"flv","x-la-asf":["lsf","lsx"],"x-mng":"mng","x-ms-asf":["asf","asx","asr"],"x-ms-wm":"wm","x-ms-wmv":"wmv","x-ms-wmx":"wmx","x-ms-wvx":"wvx","x-msvideo":"avi","x-sgi-movie":"movie","x-matroska":["mpv","mkv","mk3d","mks"],"3gpp2":"3g2",h261:"h261",h263:"h263",h264:"h264",jpeg:"jpgv",jpm:["jpm","jpgm"],mj2:["mj2","mjp2"],"vnd.ms-playready.media.pyv":"pyv","vnd.uvvu.mp4":["uvu","uvvu"],"vnd.vivo":"viv",webm:"webm","x-f4v":"f4v","x-m4v":"m4v","x-ms-vob":"vob","x-smv":"smv"}},Qn=(function(){let h,t,e,i;const n={};for(h in Te)if(Te.hasOwnProperty(h)){for(t in Te[h])if(Te[h].hasOwnProperty(t))if(e=Te[h][t],typeof e=="string")n[e]=h+"/"+t;else for(i=0;i<e.length;i++)n[e[i]]=h+"/"+t}return n})(),Jn="text/plain";function ts(h){return h&&Qn[h.split(".").pop().toLowerCase()]||Jn}const ge={lookup:ts};class es{constructor(t,e){this.settings={replacements:e&&e.replacements||"base64",archive:e&&e.archive,resolver:e&&e.resolver,request:e&&e.request},this.process(t)}process(t){this.manifest=t,this.resources=Object.keys(t).map(function(e){return t[e]}),this.replacementUrls=[],this.html=[],this.assets=[],this.css=[],this.urls=[],this.cssUrls=[],this.split(),this.splitUrls()}split(){this.html=this.resources.filter(function(t){if(t.type==="application/xhtml+xml"||t.type==="text/html")return!0}),this.assets=this.resources.filter(function(t){if(t.type!=="application/xhtml+xml"&&t.type!=="text/html")return!0}),this.css=this.resources.filter(function(t){if(t.type==="text/css")return!0})}splitUrls(){this.urls=this.assets.map((function(t){return t.href}).bind(this)),this.cssUrls=this.css.map(function(t){return t.href})}createUrl(t){const e=new Pt(t),i=ge.lookup(e.filename);return this.settings.archive?this.settings.archive.createUrl(t,{base64:this.settings.replacements==="base64"}):this.settings.replacements==="base64"?this.settings.request(t,"blob").then(n=>Hi(n)).then(n=>ai(n,i)):this.settings.request(t,"blob").then(n=>We(n,i))}replacements(){if(this.settings.replacements==="none")return new Promise((function(e){e(this.urls)}).bind(this));const t=this.urls.map(e=>{const i=this.settings.resolver(e);return this.createUrl(i).catch(n=>(console.error(n),null))});return Promise.all(t).then(e=>(this.replacementUrls=e.filter(i=>typeof i=="string"),e))}replaceCss(t,e){const i=[];return t=t||this.settings.archive,e=e||this.settings.resolver,this.cssUrls.forEach((function(n){const s=this.createCssFile(n,t,e).then((function(r){const o=this.urls.indexOf(n);o>-1&&(this.replacementUrls[o]=r)}).bind(this));i.push(s)}).bind(this)),Promise.all(i)}createCssFile(t){let e;if(ee.isAbsolute(t))return new Promise(function(r){r()});const i=this.settings.resolver(t);let n;this.settings.archive?n=this.settings.archive.getText(i):n=this.settings.request(i,"text");const s=this.urls.map(r=>{const o=this.settings.resolver(r);return new Zt(i).relative(o)});return n?n.then(r=>(r=Ci(r,s,this.replacementUrls),this.settings.replacements==="base64"?e=ai(r,"text/css"):e=We(r,"text/css"),e),r=>new Promise(function(o){o()})):new Promise(function(r){r()})}relativeTo(t,e){return e=e||this.settings.resolver,this.urls.map((function(i){const n=e(i);return new Zt(t).relative(n)}).bind(this))}get(t){const e=this.urls.indexOf(t);if(e!==-1)return this.replacementUrls.length?new Promise((function(i,n){i(this.replacementUrls[e])}).bind(this)):this.createUrl(t)}substitute(t,e){let i;return e?i=this.relativeTo(e):i=this.urls,Ci(t,i,this.replacementUrls)}destroy(){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}}class ni{constructor(t){this.pages=[],this.locations=[],this.epubcfi=new et,this.firstPage=0,this.lastPage=0,this.totalPages=0,this.toc=void 0,this.ncx=void 0,t&&(this.pageList=this.parse(t)),this.pageList&&this.pageList.length&&this.process(this.pageList)}parse(t){const e=lt(t,"html"),i=lt(t,"ncx");return e?this.parseNav(t):i?this.parseNcx(t):[]}parseNav(t){const e=Fe(t,"nav","page-list"),i=e?Array.from(Kt(e,"li")):[],n=i.length;let s;const r=[];let o;if(!i||n===0)return r;for(s=0;s<n;++s)o=this.item(i[s]),r.push(o);return r}parseNcx(t){const e=[];let i=0,n,s=0;const r=lt(t,"pageList");if(!r)return e;const o=Kt(r,"pageTarget");if(s=o.length,!o||o.length===0)return e;for(i=0;i<s;++i)n=this.ncxItem(o[i]),e.push(n);return e}ncxItem(t){const e=lt(t,"navLabel"),n=lt(e,"text").textContent??"",r=lt(t,"content").getAttribute("src")??"",o=parseInt(n,10);return{href:r,page:o}}item(t){const e=lt(t,"a"),i=e.getAttribute("href")||"",n=e.textContent||"",s=parseInt(n),r=i.indexOf("epubcfi");let o,l,f;return r!=-1?(o=i.split("#"),l=o[0],f=o.length>1?o[1]:void 0,{cfi:f,href:i,packageUrl:l,page:s}):{href:i,page:s}}process(t){t.forEach(function(e){this.pages.push(e.page),e.cfi&&this.locations.push(e.cfi)},this),this.firstPage=this.pages[0],this.lastPage=this.pages[this.pages.length-1],this.totalPages=this.lastPage-this.firstPage}pageFromCfi(t){let e=-1;if(this.locations.length===0)return-1;let i=ze(t,this.locations,this.epubcfi.compare);return i!=-1?e=this.pages[i]:(i=me(t,this.locations,this.epubcfi.compare),e=i-1>=0?this.pages[i-1]:this.pages[0],e!==void 0||(e=-1)),e}cfiFromPage(t){let e=-1;typeof t!="number"&&(t=parseInt(t));const i=this.pages.indexOf(t);return i!=-1&&(e=this.locations[i]),e}pageFromPercentage(t){return Math.round(this.totalPages*t)}percentageFromPage(t){const e=(t-this.firstPage)/this.totalPages;return Math.round(e*1e3)/1e3}percentageFromCfi(t){const e=this.pageFromCfi(t);return this.percentageFromPage(e)}destroy(){this.pages=void 0,this.locations=void 0,this.epubcfi=void 0,this.pageList=void 0,this.toc=void 0,this.ncx=void 0}}class mi{constructor(t){this.settings=t,this.name=t.layout||"reflowable",this._spread=t.spread!=="none",this._minSpreadWidth=t.minSpreadWidth||800,this._evenSpreads=t.evenSpreads||!1,t.flow==="scrolled"||t.flow==="scrolled-continuous"||t.flow==="scrolled-doc"?this._flow="scrolled":this._flow="paginated",this.width=0,this.height=0,this.spreadWidth=0,this.delta=0,this.columnWidth=0,this.gap=0,this.divisor=1,this.props={name:this.name,spread:this._spread,flow:this._flow,width:0,height:0,spreadWidth:0,delta:0,columnWidth:0,gap:0,divisor:1}}flow(t){return typeof t<"u"&&(t==="scrolled"||t==="scrolled-continuous"||t==="scrolled-doc"?this._flow="scrolled":this._flow="paginated",this.update({flow:this._flow})),this._flow}spread(t,e){return t&&(this._spread=t!=="none",this.update({spread:this._spread})),e!==void 0&&e>=0&&(this._minSpreadWidth=e),this._spread}calculate(t,e,i){let n=1,s=i||0,r=t;const o=e,l=Math.floor(r/12);let f,m;this._spread&&r>=this._minSpreadWidth?n=2:n=1,this.name==="reflowable"&&this._flow==="paginated"&&!(i!==void 0&&i>=0)&&(s=l%2===0?l:l-1),this.name==="pre-paginated"&&(s=0),n>1?(f=r/n-s,m=f+s):(f=r,m=r),this.name==="pre-paginated"&&n>1&&(r=f);const b=f*n+s,E=r;this.width=r,this.height=o,this.spreadWidth=b,this.pageWidth=m,this.delta=E,this.columnWidth=f,this.gap=s,this.divisor=n,this.update({width:r,height:o,spreadWidth:b,pageWidth:m,delta:E,columnWidth:f,gap:s,divisor:n})}format(t,e,i){let n;return this.name==="pre-paginated"?n=t.fit(this.columnWidth,this.height,e):this._flow==="paginated"?n=t.columns(this.width,this.height,this.columnWidth,this.gap,this.settings.direction):i&&i==="horizontal"?n=t.size(void 0,this.height):n=t.size(this.width,void 0),n}count(t,e){let i,n;return this.name==="pre-paginated"?(i=1,n=1):this._flow==="paginated"?(e=e||this.delta,i=Math.ceil(t/e),n=i*this.divisor):(e=e||this.height,i=Math.ceil(t/e),n=i),{spreads:i,pages:n}}update(t){const e=t,i=this.props;if(Object.keys(e).forEach(n=>{i[n]===e[n]&&delete e[n]}),Object.keys(e).length>0){const n=xt(this.props,t);this.emit(M.LAYOUT.UPDATED,n,t)}}}Wt(mi.prototype);class is{constructor(t){this.rendition=t,this._themes={default:{rules:{},url:"",serialized:""}},this._overrides={},this._current="default",this._injected=[],this.rendition.hooks.content.register(this.inject.bind(this)),this.rendition.hooks.content.register(this.overrides.bind(this))}register(...t){if(arguments.length!==0){if(arguments.length===1&&typeof arguments[0]=="object")return this.registerThemes(arguments[0]);if(arguments.length===1&&typeof arguments[0]=="string")return this.default(arguments[0]);if(arguments.length===2&&typeof arguments[1]=="string")return this.registerUrl(arguments[0],arguments[1]);if(arguments.length===2&&typeof arguments[1]=="object")return this.registerRules(arguments[0],arguments[1])}}default(t){if(t){if(typeof t=="string")return this.registerUrl("default",t);if(typeof t=="object")return this.registerRules("default",t)}}registerThemes(t){for(const e in t)if(t.hasOwnProperty(e)){const i=t[e];typeof i=="string"?this.registerUrl(e,i):this.registerRules(e,i)}}registerCss(t,e){this._themes[t]={serialized:e},(this._injected[t]||t=="default")&&this.update(t)}registerUrl(t,e){const i=new Pt(e);this._themes[t]={url:i.toString()},(this._injected[t]||t=="default")&&this.update(t)}registerRules(t,e){this._themes[t]={rules:e},(this._injected[t]||t=="default")&&this.update(t)}select(t){const e=this._current;this._current=t,this.update(t),this.rendition.getContents().forEach(n=>{n.removeClass(e),n.addClass(t)})}update(t){this.rendition.getContents().forEach(i=>{this.add(t,i)})}inject(t){const e=[],i=this._themes;let n;for(const s in i)i.hasOwnProperty(s)&&(s===this._current||s==="default")&&(n=i[s],(n.rules&&Object.keys(n.rules).length>0||n.url&&e.indexOf(n.url)===-1)&&this.add(s,t),this._injected.push(s));this._current!="default"&&t.addClass(this._current)}add(t,e){const 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))}override(t,e,i){const n=this.rendition.getContents();this._overrides[t]={value:e,priority:i===!0},n.forEach(s=>{s.css(t,this._overrides[t].value,this._overrides[t].priority)})}removeOverride(t){const e=this.rendition.getContents();delete this._overrides[t],e.forEach(i=>{i.css(t)})}overrides(t){const e=this._overrides;for(const i in e)e.hasOwnProperty(i)&&t.css(i,e[i].value,e[i].priority)}fontSize(t){this.override("font-size",t)}font(t){this.override("font-family",t,!0)}destroy(){this.rendition=void 0,this._themes=void 0,this._overrides=void 0,this._current=void 0,this._injected=void 0}}class ns{constructor(t){this.rendition=t,this.highlights=[],this.underlines=[],this.marks=[],this._annotations={},this._annotationsBySectionIndex={},this.rendition.hooks.render.register(this.inject.bind(this)),this.rendition.hooks.unloaded.register(this.clear.bind(this))}add(t,e,i,n,s,r){const o=encodeURI(e+t),f=new et(e).spinePos,m=new Gi({type:t,cfiRange:e,data:i,sectionIndex:f,cb:n,className:s,styles:r});return this._annotations[o]=m,f in this._annotationsBySectionIndex?this._annotationsBySectionIndex[f].push(o):this._annotationsBySectionIndex[f]=[o],this.rendition.views().forEach(E=>{m.sectionIndex===E.index&&m.attach(E)}),m}remove(t,e){const i=encodeURI(t+e);if(i in this._annotations){const n=this._annotations[i];if(e&&n.type!==e)return;this.rendition.views().forEach(r=>{this._removeFromAnnotationBySectionIndex(n.sectionIndex,i),n.sectionIndex===r.index&&n.detach(r)}),delete this._annotations[i]}}_removeFromAnnotationBySectionIndex(t,e){this._annotationsBySectionIndex[t]=this._annotationsAt(t).filter(i=>i!==e)}_annotationsAt(t){return this._annotationsBySectionIndex[t]}highlight(t,e,i,n,s){return this.add("highlight",t,e,i,n,s)}underline(t,e,i,n,s){return this.add("underline",t,e,i,n,s)}mark(t,e,i){return this.add("mark",t,e,i)}each(...t){return this._annotations.forEach.apply(this._annotations,arguments)}inject(t){const e=t.index;e in this._annotationsBySectionIndex&&this._annotationsBySectionIndex[e].forEach(n=>{this._annotations[n].attach(t)})}clear(t){const e=t.index;e in this._annotationsBySectionIndex&&this._annotationsBySectionIndex[e].forEach(n=>{this._annotations[n].detach(t)})}show(){}hide(){}}class Gi{constructor({type:t,cfiRange:e,data:i,sectionIndex:n,cb:s,className:r,styles:o}){this.type=t,this.cfiRange=e,this.data=i??{},this.sectionIndex=n??0,this.mark=void 0,this.cb=s,this.className=r??"",this.styles=o??{}}update(t){this.data=t}attach(t){const{cfiRange:e,data:i,type:n,mark:s,cb:r,className:o,styles:l}=this;let f;return n==="highlight"?f=t.highlight(e,i,r,o,l):n==="underline"?f=t.underline(e,i,r,o,l):n==="mark"&&(f=t.mark(e,i,r)),this.mark=f,this.emit(M.ANNOTATION.ATTACH,f),f}detach(t){const{cfiRange:e,type:i}=this;let n;return t&&(i==="highlight"?n=t.unhighlight(e):i==="underline"?n=t.ununderline(e):i==="mark"&&(n=t.unmark(e))),this.mark=void 0,this.emit(M.ANNOTATION.DETACH,n),n}text(){}}Wt(Gi.prototype);class je{constructor(t,e,i,n=!1){this.layout=t,this.horizontal=i==="horizontal",this.direction=e||"ltr",this._dev=n}section(t){const e=this.findRanges(t);return this.rangeListToCfiList(t.section.cfiBase,e)}page(t,e,i,n){const s=t&&t.document?t.document.body:!1;if(!s)return;const r=this.rangePairToCfiPair(e,{start:this.findStart(s,i,n),end:this.findEnd(s,i,n)});if(this._dev===!0){const o=t.document,l=new et(r.start).toRange(o),f=new et(r.end).toRange(o),m=o.defaultView.getSelection(),b=o.createRange();m.removeAllRanges(),b.setStart(l.startContainer,l.startOffset),b.setEnd(f.endContainer,f.endOffset),m.addRange(b)}return r}walk(t,e){if(t&&t.nodeType===Node.TEXT_NODE)return;const i={acceptNode:function(l){return l.data.trim().length>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}},n=i.acceptNode;n.acceptNode=i.acceptNode;const s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,n);let r,o;for(;(r=s.nextNode())&&(o=e(r),!o););return o}findRanges(t){const e=[],i=t.contents.scrollWidth(),s=Math.ceil(i/this.layout.spreadWidth)*this.layout.divisor,r=this.layout.columnWidth,o=this.layout.gap;let l,f;for(let m=0;m<s;m++)l=(r+o)*m,f=r*(m+1)+o*m,e.push({start:this.findStart(t.document.body,l,f),end:this.findEnd(t.document.body,l,f)});return e}findStart(t,e,i){const n=[t];let s,r,o=t;for(;n.length;)if(s=n.shift(),r=this.walk(s,l=>{let f,m,b,E;const N=oi(l);if(this.horizontal&&this.direction==="ltr"){if(f=this.horizontal?N.left:N.top,m=this.horizontal?N.right:N.bottom,f>=e&&f<=i)return l;if(m>e)return l;o=l,n.push(l)}else if(this.horizontal&&this.direction==="rtl"){if(f=N.left,m=N.right,m<=i&&m>=e)return l;if(f<i)return l;o=l,n.push(l)}else{if(b=N.top,E=N.bottom,b>=e&&b<=i)return l;if(E>e)return l;o=l,n.push(l)}}),r)return this.findTextStartRange(r,e,i);return this.findTextStartRange(o,e,i)}findEnd(t,e,i){const n=[t];let s,r=t,o;for(;n.length;)if(s=n.shift(),o=this.walk(s,l=>{let f,m,b,E;const N=oi(l);if(this.horizontal&&this.direction==="ltr"){if(f=Math.round(N.left),m=Math.round(N.right),f>i&&r)return r;if(m>i)return l;r=l,n.push(l)}else if(this.horizontal&&this.direction==="rtl"){if(f=Math.round(this.horizontal?N.left:N.top),m=Math.round(this.horizontal?N.right:N.bottom),m<e&&r)return r;if(f<e)return l;r=l,n.push(l)}else{if(b=Math.round(N.top),E=Math.round(N.bottom),b>i&&r)return r;if(E>i)return l;r=l,n.push(l)}}),o)return this.findTextEndRange(o,e,i);return this.findTextEndRange(r,e,i)}findTextStartRange(t,e,i){const n=this.splitTextNodeIntoRanges(t);let s,r,o,l,f;for(let m=0;m<n.length;m++)if(s=n[m],r=s.getBoundingClientRect(),this.horizontal&&this.direction==="ltr"){if(o=r.left,o>=e)return s}else if(this.horizontal&&this.direction==="rtl"){if(f=r.right,f<=i)return s}else if(l=r.top,l>=e)return s;return n[0]}findTextEndRange(t,e,i){const n=this.splitTextNodeIntoRanges(t);let s,r,o,l,f,m,b;for(let E=0;E<n.length;E++){if(r=n[E],o=r.getBoundingClientRect(),this.horizontal&&this.direction==="ltr"){if(l=o.left,f=o.right,l>i&&s)return s;if(f>i)return r}else if(this.horizontal&&this.direction==="rtl"){if(l=o.left,f=o.right,f<e&&s)return s;if(l<e)return r}else{if(m=o.top,b=o.bottom,m>i&&s)return s;if(b>i)return r}s=r}return n[n.length-1]}splitTextNodeIntoRanges(t,e){const i=[],s=(t.textContent||"").trim();let r;const o=t.ownerDocument,l=e||" ";let f=s.indexOf(l);if(f===-1||t.nodeType!=Node.TEXT_NODE)return r=o.createRange(),r.selectNodeContents(t),[r];for(r=o.createRange(),r.setStart(t,0),r.setEnd(t,f),i.push(r),r=null;f!=-1;)f=s.indexOf(l,f+1),f>0&&(r&&(r.setEnd(t,f),i.push(r)),r=o.createRange(),r.setStart(t,f+1));return r&&(r.setEnd(t,s.length),i.push(r)),i}rangePairToCfiPair(t,e){const i=e.start,n=e.end;i.collapse(!0),n.collapse(!1);const s=new et(i,t).toString(),r=new et(n,t).toString();return{start:s,end:r}}rangeListToCfiList(t,e){const i=[];let n;for(let s=0;s<e.length;s++)n=this.rangePairToCfiPair(t,e[s]),i.push(n);return i}axis(t){return t&&(this.horizontal=t==="horizontal"),this.horizontal}}const Ki=typeof navigator<"u",ss=Ki&&/Chrome/.test(navigator.userAgent),Ii=Ki&&!ss&&/AppleWebKit/.test(navigator.userAgent),rs=1;class $e{constructor(t,e,i,n){this.epubcfi=new et,this.document=t,this.documentElement=this.document.documentElement,this.content=e||this.document.body,this.window=this.document.defaultView,this._size={width:0,height:0},this.sectionIndex=n||0,this.cfiBase=i||"",this.epubReadingSystem("epub.js",Ye),this.called=0,this.active=!0,this.listeners()}static get listenedEvents(){return Me}width(t){const e=this.content;return t&&ut(t)&&(t=t+"px"),t&&(e.style.width=t),parseInt(this.window.getComputedStyle(e).width)}height(t){const e=this.content;return t&&ut(t)&&(t=t+"px"),t&&(e.style.height=t),parseInt(this.window.getComputedStyle(e).height)}contentWidth(t){const e=this.content||this.document.body;return t&&ut(t)&&(t=t+"px"),t&&(e.style.width=t),parseInt(this.window.getComputedStyle(e).width)}contentHeight(t){const e=this.content||this.document.body;return t&&ut(t)&&(t=t+"px"),t&&(e.style.height=t),parseInt(this.window.getComputedStyle(e).height)}textWidth(){let t;const e=this.document.createRange(),i=this.content||this.document.body,n=Be(i);return e.selectNodeContents(i),t=e.getBoundingClientRect().width,n&&n.width&&(t+=n.width),Math.round(t)}textHeight(){const t=this.document.createRange(),e=this.content||this.document.body;t.selectNodeContents(e);const n=t.getBoundingClientRect().bottom;return Math.round(n)}scrollWidth(){return this.documentElement.scrollWidth}scrollHeight(){return this.documentElement.scrollHeight}overflow(t){return t&&(this.documentElement.style.overflow=t),this.window.getComputedStyle(this.documentElement).overflow}overflowX(t){return t&&(this.documentElement.style.overflowX=t),this.window.getComputedStyle(this.documentElement).overflowX}overflowY(t){return t&&(this.documentElement.style.overflowY=t),this.window.getComputedStyle(this.documentElement).overflowY}css(t,e,i){const n=this.content||this.document.body;return e?n.style.setProperty(t,e,i?"important":""):n.style.removeProperty(t),this.window.getComputedStyle(n)[t]}viewport(t){let e=this.document.querySelector("meta[name='viewport']");const i={width:void 0,height:void 0,scale:void 0,minimum:void 0,maximum:void 0,scalable:void 0},n=[];let s={};if(e&&e.hasAttribute("content")){const r=e.getAttribute("content")??"",o=r.match(/width\s*=\s*([^,]*)/),l=r.match(/height\s*=\s*([^,]*)/),f=r.match(/initial-scale\s*=\s*([^,]*)/),m=r.match(/minimum-scale\s*=\s*([^,]*)/),b=r.match(/maximum-scale\s*=\s*([^,]*)/),E=r.match(/user-scalable\s*=\s*([^,]*)/);o&&o.length&&typeof o[1]<"u"&&(i.width=o[1]),l&&l.length&&typeof l[1]<"u"&&(i.height=l[1]),f&&f.length&&typeof f[1]<"u"&&(i.scale=f[1]),m&&m.length&&typeof m[1]<"u"&&(i.minimum=m[1]),b&&b.length&&typeof b[1]<"u"&&(i.maximum=b[1]),E&&E.length&&typeof E[1]<"u"&&(i.scalable=E[1])}return s=Ui(t||{},i),t&&(s.width&&n.push("width="+s.width),s.height&&n.push("height="+s.height),s.scale&&n.push("initial-scale="+s.scale),s.scalable==="no"?(n.push("minimum-scale="+s.scale),n.push("maximum-scale="+s.scale),n.push("user-scalable="+s.scalable)):(s.scalable&&n.push("user-scalable="+s.scalable),s.minimum&&n.push("minimum-scale="+s.minimum),s.maximum&&n.push("minimum-scale="+s.maximum)),e||(e=this.document.createElement("meta"),e.setAttribute("name","viewport"),this.document.querySelector("head").appendChild(e)),e.setAttribute("content",n.join(", ")),this.window.scrollTo(0,0)),s}expand(){this.emit(M.CONTENTS.EXPAND)}listeners(){this.imageLoadListeners(),this.mediaQueryListeners(),this.addEventListeners(),this.addSelectionListeners(),typeof ResizeObserver>"u"?(this.resizeListeners(),this.visibilityListeners()):this.resizeObservers(),this.linksHandler()}removeListeners(){this.removeEventListeners(),this.removeSelectionListeners(),this.observer&&this.observer.disconnect(),clearTimeout(this.expanding)}resizeCheck(){const t=this.textWidth(),e=this.textHeight();(t!=this._size.width||e!=this._size.height)&&(this._size={width:t,height:e},this.onResize&&this.onResize(this._size),this.emit(M.CONTENTS.RESIZE,this._size))}resizeListeners(){clearTimeout(this.expanding),requestAnimationFrame(this.resizeCheck.bind(this)),this.expanding=setTimeout(this.resizeListeners.bind(this),350)}visibilityListeners(){document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&this.active===!1?(this.active=!0,this.resizeListeners()):(this.active=!1,clearTimeout(this.expanding))})}transitionListeners(){const t=this.content;t.style.transitionProperty="font, font-size, font-size-adjust, font-stretch, font-variation-settings, font-weight, width, height",t.style.transitionDuration="0.001ms",t.style.transitionTimingFunction="linear",t.style.transitionDelay="0",this._resizeCheck=this.resizeCheck.bind(this),this.document.addEventListener("transitionend",this._resizeCheck)}mediaQueryListeners(){const t=this.document.styleSheets,e=(function(i){i.matches&&!this._expanding&&setTimeout(this.expand.bind(this),1)}).bind(this);for(let i=0;i<t.length;i+=1){let n;try{n=t[i].cssRules}catch{return}if(!n)return;for(let s=0;s<n.length;s+=1)n[s].media&&this.window.matchMedia(n[s].media.mediaText).addListener(e)}}resizeObservers(){this.observer=new ResizeObserver(t=>{requestAnimationFrame(this.resizeCheck.bind(this))}),this.observer.observe(this.document.documentElement)}mutationObservers(){this.observer=new MutationObserver(e=>{this.resizeCheck()});const t={attributes:!0,childList:!0,characterData:!0,subtree:!0};this.observer.observe(this.document,t)}imageLoadListeners(){const t=this.document.querySelectorAll("img");let e;for(let i=0;i<t.length;i++)e=t[i],typeof e.naturalWidth<"u"&&e.naturalWidth===0&&(e.onload=this.expand.bind(this))}fontLoadListeners(){!this.document||!this.document.fonts||this.document.fonts.ready.then((function(){this.resizeCheck()}).bind(this))}root(){return this.document?this.document.documentElement:null}locationOf(t,e){let i;const n={left:0,top:0};if(!this.document)return n;if(this.epubcfi.isCfiString(t)){const s=new et(t).toRange(this.document,e);if(s){try{if(!s.endContainer||s.startContainer==s.endContainer&&s.startOffset==s.endOffset){let r=(s.startContainer.textContent??"").indexOf(" ",s.startOffset);r==-1&&(r=(s.startContainer.textContent??"").length),s.setEnd(s.startContainer,r)}}catch(r){console.error("setting end offset to start container length failed",r)}if(s.startContainer.nodeType===Node.ELEMENT_NODE)i=s.startContainer.getBoundingClientRect(),n.left=i.left,n.top=i.top;else if(Ii){const r=s.startContainer,o=new Range;try{r.nodeType===rs?i=r.getBoundingClientRect():s.startOffset+2<r.length?(o.setStart(r,s.startOffset),o.setEnd(r,s.startOffset+2),i=o.getBoundingClientRect()):s.startOffset-2>0?(o.setStart(r,s.startOffset-2),o.setEnd(r,s.startOffset),i=o.getBoundingClientRect()):i=r.parentNode.getBoundingClientRect()}catch(l){console.error(l,l.stack)}}else i=s.getBoundingClientRect()}}else if(typeof t=="string"&&t.indexOf("#")>-1){const s=t.substring(t.indexOf("#")+1),r=this.document.getElementById(s);if(r)if(Ii){const o=new Range;o.selectNode(r),i=o.getBoundingClientRect()}else i=r.getBoundingClientRect()}return i&&(n.left=i.left,n.top=i.top),n}addStylesheet(t){return new Promise((function(e,i){let n,s=!1;if(!this.document){e(!1);return}if(n=this.document.querySelector("link[href='"+t+"']"),n){e(!0);return}n=this.document.createElement("link"),n.type="text/css",n.rel="stylesheet",n.href=t,n.onload=n.onreadystatechange=function(){!s&&(!this.readyState||this.readyState=="complete")&&(s=!0,setTimeout(()=>{e(!0)},1))},this.document.head.appendChild(n)}).bind(this))}_getStylesheetNode(t){let e;return t="epubjs-inserted-css-"+(t||""),this.document?(e=this.document.getElementById(t),e||(e=this.document.createElement("style"),e.id=t,this.document.head.appendChild(e)),e):!1}addStylesheetCss(t,e){if(!this.document||!t)return!1;const i=this._getStylesheetNode(e);return i?(i.innerHTML=t,!0):!1}addStylesheetRules(t,e){if(!this.document||!t||t.length===0)return;const i=this._getStylesheetNode(e).sheet;if(Object.prototype.toString.call(t)==="[object Array]")for(let n=0,s=t.length;n<s;n++){let r=1,o=t[n],l="";const f=t[n][0];Object.prototype.toString.call(o[1][0])==="[object Array]"&&(o=o[1],r=0);for(let m=o.length;r<m;r++){const b=o[r];l+=b[0]+":"+b[1]+(b[2]?" !important":"")+`;
4
+ `}i.insertRule(f+"{"+l+"}",i.cssRules.length)}else Object.keys(t).forEach(s=>{const r=t[s];if(Array.isArray(r))r.forEach(o=>{const f=Object.keys(o).map(m=>`${m}:${o[m]}`).join(";");i.insertRule(`${s}{${f}}`,i.cssRules.length)});else{const l=Object.keys(r).map(f=>`${f}:${r[f]}`).join(";");i.insertRule(`${s}{${l}}`,i.cssRules.length)}})}addScript(t){return new Promise((function(e,i){let n=!1;if(!this.document){e(!1);return}const s=this.document.createElement("script");s.type="text/javascript",s.async=!0,s.src=t,s.onload=s.onreadystatechange=function(){!n&&(!this.readyState||this.readyState=="complete")&&(n=!0,setTimeout(function(){e(!0)},1))},this.document.head.appendChild(s)}).bind(this))}addClass(t){if(!this.document)return;const e=this.content||this.document.body;e&&e.classList.add(t)}removeClass(t){if(!this.document)return;const e=this.content||this.document.body;e&&e.classList.remove(t)}addEventListeners(){this.document&&(this._triggerEvent=this.triggerEvent.bind(this),Me.forEach(function(t){this.document.addEventListener(t,this._triggerEvent,{passive:!0})},this))}removeEventListeners(){this.document&&(Me.forEach(function(t){this.document.removeEventListener(t,this._triggerEvent,{passive:!0})},this),this._triggerEvent=void 0)}triggerEvent(t){this.emit(t.type,t)}addSelectionListeners(){this.document&&(this._onSelectionChange=this.onSelectionChange.bind(this),this.document.addEventListener("selectionchange",this._onSelectionChange,{passive:!0}))}removeSelectionListeners(){this.document&&(this.document.removeEventListener("selectionchange",this._onSelectionChange),this._onSelectionChange=void 0)}onSelectionChange(t){this.selectionEndTimeout&&clearTimeout(this.selectionEndTimeout),this.selectionEndTimeout=setTimeout((function(){const e=this.window.getSelection();this.triggerSelectedEvent(e)}).bind(this),250)}triggerSelectedEvent(t){let e,i;t&&t.rangeCount>0&&(e=t.getRangeAt(0),e.collapsed||(i=new et(e,this.cfiBase).toString(),this.emit(M.CONTENTS.SELECTED,i),this.emit(M.CONTENTS.SELECTED_RANGE,e)))}range(t,e){return new et(t).toRange(this.document,e)}cfiFromRange(t,e){return new et(t,this.cfiBase,e).toString()}cfiFromNode(t,e){return new et(t,this.cfiBase,e).toString()}map(t){return new je(t).section(void 0)}size(t,e){const i={scale:1,scalable:"no"};this.layoutStyle("scrolling"),t!==void 0&&t>=0&&(this.width(t),i.width=t,this.css("padding","0 "+t/12+"px")),e!==void 0&&e>=0&&(this.height(e),i.height=e),this.css("margin","0"),this.css("box-sizing","border-box"),this.viewport(i)}columns(t,e,i,n,s){const r=de("column-axis"),o=de("column-gap"),l=de("column-width"),f=de("column-fill"),b=this.writingMode().indexOf("vertical")===0?"vertical":"horizontal";this.layoutStyle("paginated"),s==="rtl"&&b==="horizontal"&&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),b==="vertical"?(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(f,"auto"),this.css(o,n+"px"),this.css(l,i+"px"),this.css("-webkit-line-box-contain","block glyphs replaced")}scaler(t,e,i){const n="scale("+t+")";let s="";this.css("transform-origin","top left"),(e!==void 0&&e>=0||i!==void 0&&i>=0)&&(s=" translate("+(e||0)+"px, "+(i||0)+"px )"),this.css("transform",n+s)}fit(t,e,i){const n=this.viewport(),s=parseInt(n.width),r=parseInt(n.height),o=t/s,l=e/r,f=o<l?o:l;if(this.layoutStyle("paginated"),this.width(s),this.height(r),this.overflow("hidden"),this.scaler(f,0,0),this.css("background-size",s*f+"px "+r*f+"px"),this.css("background-color","transparent"),i&&i.properties.includes("page-spread-left")){const m=t-s*f;this.css("margin-left",m+"px")}}direction(t){this.documentElement&&(this.documentElement.style.direction=t)}mapPage(t,e,i,n,s){return new je(e,void 0,void 0,s).page(this,t,i,n)}linksHandler(){$n(this.content,t=>{this.emit(M.CONTENTS.LINK_CLICKED,t)})}writingMode(t){const e=de("writing-mode");return t&&this.documentElement&&(this.documentElement.style[e]=t),this.window.getComputedStyle(this.documentElement)[e]||""}layoutStyle(t){return t&&(this._layoutStyle=t,navigator.epubReadingSystem.layoutStyle=this._layoutStyle),this._layoutStyle||"paginated"}epubReadingSystem(t,e){return navigator.epubReadingSystem={name:t,version:e,layoutStyle:this.layoutStyle(),hasFeature:function(i){switch(i){case"dom-manipulation":return!0;case"layout-changes":return!0;case"touch-events":return!0;case"mouse-events":return!0;case"keyboard-events":return!0;case"spine-scripting":return!1;default:return!1}}},navigator.epubReadingSystem}destroy(){this.removeListeners()}}Wt($e.prototype);function Re(h){return document.createElementNS("http://www.w3.org/2000/svg",h)}function os(h,t){function e(n){for(let s=t.length-1;s>=0;s--){const r=t[s];let o=n.clientX,l=n.clientY;if(n.touches&&n.touches.length&&(o=n.touches[0].clientX,l=n.touches[0].clientY),!!hs(r,h,o,l)){r.dispatchEvent(as(n));break}}}let i;if(h.nodeName==="iframe"||h.nodeName==="IFRAME")try{i=h.contentDocument}catch{i=h}else i=h;for(const n of["mouseup","mousedown","click","touchstart"])i.addEventListener(n,s=>e(s),!1)}function as(h){const t=Object.assign({},h,{bubbles:!1});try{return new MouseEvent(h.type,t)}catch{const i=document.createEvent("MouseEvents");return i.initMouseEvent(h.type,!1,t.cancelable,t.view,t.detail,t.screenX,t.screenY,t.clientX,t.clientY,t.ctrlKey,t.altKey,t.shiftKey,t.metaKey,t.button,t.relatedTarget),i}}function hs(h,t,e,i){const n=t.getBoundingClientRect();function s(l,f,m){const b=l.top-n.top,E=l.left-n.left,N=b+l.height,W=E+l.width;return b<=m&&E<=f&&N>m&&W>f}const r=h.getBoundingClientRect();if(!s(r,e,i))return!1;const o=h.getClientRects();for(let l=0,f=o.length;l<f;l++)if(s(o[l],e,i))return!0;return!1}function ls(h,t){const e=t.getBoundingClientRect(),i=h.getBoundingClientRect();return{top:i.top-e.top,left:i.left-e.left,height:h.scrollHeight,width:h.scrollWidth}}function cs(h,t){h.style.setProperty("top",`${t.top}px`,"important"),h.style.setProperty("left",`${t.left}px`,"important"),h.style.setProperty("height",`${t.height}px`,"important"),h.style.setProperty("width",`${t.width}px`,"important")}function us(h,t){return t.right<=h.right&&t.left>=h.left&&t.top>=h.top&&t.bottom<=h.bottom}class Ai{constructor(t,e=document.body){this.target=t,this.element=Re("svg"),this.marks=[],this.element.style.position="absolute",this.element.setAttribute("pointer-events","none"),os(this.target,this.marks),this.container=e,this.container.appendChild(this.element),this.render()}addMark(t){const e=Re("g");return this.element.appendChild(e),t.bind(e,this.container),this.marks.push(t),t.render(),t}removeMark(t){const e=this.marks.indexOf(t);if(e===-1)return;const i=t.unbind();this.element.removeChild(i),this.marks.splice(e,1)}render(){cs(this.element,ls(this.target,this.container));for(const t of this.marks)t.render()}}class ds{constructor(){this.element=null}bind(t,e){this.element=t,this.container=e}unbind(){const t=this.element;return this.element=null,t}render(){}dispatchEvent(t){this.element&&this.element.dispatchEvent(t)}getBoundingClientRect(){return this.element.getBoundingClientRect()}getClientRects(){const t=[];let e=this.element.firstChild;for(;e;)t.push(e.getBoundingClientRect()),e=e.nextSibling;return t}filteredRanges(){const t=Array.from(this.range.getClientRects());return t.filter(e=>{for(let i=0;i<t.length;i++){if(t[i]===e)return!0;if(us(t[i],e))return!1}return!0})}}class Zi extends ds{constructor(t,e,i,n){super(),this.range=t,this.className=e,this.data=i||{},this.attributes=n||{}}bind(t,e){super.bind(t,e);for(const i in this.data)this.data.hasOwnProperty(i)&&(this.element.dataset[i]=this.data[i]);for(const i in this.attributes)this.attributes.hasOwnProperty(i)&&this.element.setAttribute(i,this.attributes[i]);this.className&&this.element.classList.add(this.className)}render(){for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);const t=this.element.ownerDocument.createDocumentFragment(),e=this.filteredRanges(),i=this.element.getBoundingClientRect(),n=this.container.getBoundingClientRect();for(let s=0,r=e.length;s<r;s++){const o=e[s],l=Re("rect");l.setAttribute("x",o.left-i.left+n.left),l.setAttribute("y",o.top-i.top+n.top),l.setAttribute("height",o.height),l.setAttribute("width",o.width),t.appendChild(l)}this.element.appendChild(t)}}class fs extends Zi{constructor(t,e,i,n){super(t,e,i,n)}render(){for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);const t=this.element.ownerDocument.createDocumentFragment(),e=this.filteredRanges(),i=this.element.getBoundingClientRect(),n=this.container.getBoundingClientRect();for(let s=0,r=e.length;s<r;s++){const o=e[s],l=Re("rect");l.setAttribute("x",o.left-i.left+n.left),l.setAttribute("y",o.top-i.top+n.top),l.setAttribute("height",o.height),l.setAttribute("width",o.width),l.setAttribute("fill","none");const f=Re("line");f.setAttribute("x1",o.left-i.left+n.left),f.setAttribute("x2",o.left-i.left+n.left+o.width),f.setAttribute("y1",o.top-i.top+n.top+o.height-1),f.setAttribute("y2",o.top-i.top+n.top+o.height-1),f.setAttribute("stroke-width",1),f.setAttribute("stroke","black"),f.setAttribute("stroke-linecap","square"),t.appendChild(l),t.appendChild(f)}this.element.appendChild(t)}}class Qi{constructor(t,e){this.settings=xt({ignoreClass:"",axis:void 0,direction:void 0,width:0,height:0,layout:void 0,globalLayoutProperties:{},method:void 0,forceRight:!1,allowScriptedContent:!1,allowPopups:!1},e||{}),this.id="epubjs-view-"+Xe(),this.section=t,this.index=t.index,this.element=this.container(this.settings.axis),this.added=!1,this.displayed=!1,this.rendered=!1,this.fixedWidth=0,this.fixedHeight=0,this.epubcfi=new et,this.layout=this.settings.layout,this.pane=void 0,this.highlights={},this.underlines={},this.marks={}}container(t){const e=document.createElement("div");return e.classList.add("epub-view"),e.style.height="0px",e.style.width="0px",e.style.overflow="hidden",e.style.position="relative",e.style.display="block",t&&t=="horizontal"?e.style.flex="none":e.style.flex="initial",e}create(){return this.iframe?this.iframe:(this.element||(this.element=this.container()),this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.style.overflow="hidden",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.sandbox="allow-same-origin",this.settings.allowScriptedContent&&(this.iframe.sandbox+=" allow-scripts"),this.settings.allowPopups&&(this.iframe.sandbox+=" allow-popups"),this.iframe.setAttribute("enable-annotation","true"),this.resizing=!0,this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.iframe.style.width="0",this.iframe.style.height="0",this._width=0,this._height=0,this.element.setAttribute("ref",String(this.index)),this.added=!0,this.elementBounds=Pe(this.element),"srcdoc"in this.iframe?this.supportsSrcdoc=!0:this.supportsSrcdoc=!1,this.settings.method||(this.settings.method=this.supportsSrcdoc?"srcdoc":"write"),this.iframe)}render(t,e){return this.create(),this.size(),this.sectionRender||(this.sectionRender=this.section.render(t)),this.sectionRender.then((function(i){return this.load(i)}).bind(this)).then((function(){const i=this.contents.writingMode();let n;return this.settings.flow==="scrolled"?n=i.indexOf("vertical")===0?"horizontal":"vertical":n=i.indexOf("vertical")===0?"vertical":"horizontal",i.indexOf("vertical")===0&&this.settings.flow==="paginated"&&(this.layout.delta=this.layout.height),this.setAxis(n),this.emit(M.VIEWS.AXIS,n),this.setWritingMode(i),this.emit(M.VIEWS.WRITING_MODE,i),this.layout.format(this.contents,this.section,this.axis),this.addListeners(),new Promise((s,r)=>{this.expand(),this.settings.forceRight&&(this.element.style.marginLeft=this.width()+"px"),s()})}).bind(this),(function(i){return this.emit(M.VIEWS.LOAD_ERROR,i),new Promise((n,s)=>{s(i)})}).bind(this)).then((function(){this.emit(M.VIEWS.RENDERED,this.section)}).bind(this))}reset(){this.iframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this._width=0,this._height=0,this._textWidth=void 0,this._contentWidth=void 0,this._textHeight=void 0,this._contentHeight=void 0),this._needsReframe=!0}size(t,e){const i=t||this.settings.width,n=e||this.settings.height;this.layout.name==="pre-paginated"?this.lock("both",i,n):this.settings.axis==="horizontal"?this.lock("height",i,n):this.lock("width",i,n),this.settings.width=i,this.settings.height=n}lock(t,e,i){const n=Be(this.element);let s;this.iframe?s=Be(this.iframe):s={width:0,height:0},t=="width"&&ut(e)&&(this.lockedWidth=e-n.width-s.width),t=="height"&&ut(i)&&(this.lockedHeight=i-n.height-s.height),t==="both"&&ut(e)&&ut(i)&&(this.lockedWidth=e-n.width-s.width,this.lockedHeight=i-n.height-s.height),this.displayed&&this.iframe&&this.expand()}expand(t){let e=this.lockedWidth,i=this.lockedHeight,n;!this.iframe||this._expanding||(this._expanding=!0,this.layout.name==="pre-paginated"?(e=this.layout.columnWidth,i=this.layout.height):this.settings.axis==="horizontal"?(e=this.contents.textWidth(),e%this.layout.pageWidth>0&&(e=Math.ceil(e/this.layout.pageWidth)*this.layout.pageWidth),this.settings.forceEvenPages&&(n=e/this.layout.pageWidth,this.layout.divisor>1&&this.layout.name==="reflowable"&&n%2>0&&(e+=this.layout.pageWidth))):this.settings.axis==="vertical"&&(i=this.contents.textHeight(),this.settings.flow==="paginated"&&i%this.layout.height>0&&(i=Math.ceil(i/this.layout.height)*this.layout.height)),(this._needsReframe||e!=this._width||i!=this._height)&&this.reframe(e,i),this._expanding=!1)}reframe(t,e){ut(t)&&(this.element.style.width=t+"px",this.iframe.style.width=t+"px",this._width=t),ut(e)&&(this.element.style.height=e+"px",this.iframe.style.height=e+"px",this._height=e);const i=this.prevBounds?t-this.prevBounds.width:t,n=this.prevBounds?e-this.prevBounds.height:e,s={width:t,height:e,widthDelta:i,heightDelta:n};this.pane&&this.pane.render(),requestAnimationFrame(()=>{let r;for(const o in this.marks)this.marks.hasOwnProperty(o)&&(r=this.marks[o],this.placeMark(r.element,r.range))}),this.onResize(this,s),this.emit(M.VIEWS.RESIZED,s),this.prevBounds=s,this.elementBounds=Pe(this.element)}load(t){const e=new st,i=e.promise;if(!this.iframe)return e.reject(new Error("No Iframe Available")),i;if(this.iframe.onload=(function(n){this.onLoad(n,e)}).bind(this),this.settings.method==="blobUrl")this.blobUrl=We(t,"application/xhtml+xml"),this.iframe.src=this.blobUrl,this.element.appendChild(this.iframe);else if(this.settings.method==="srcdoc")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.document.open(),window.MSApp&&window.MSApp.execUnsafeLocalFunction){const n=this;window.MSApp.execUnsafeLocalFunction(function(){n.document.write(t)})}else this.document.write(t);this.document.close()}return i}onLoad(t,e){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,this.contents=new $e(this.document,this.document.body,this.section.cfiBase,this.section.index),this.rendering=!1;let i=this.document.querySelector("link[rel='canonical']");i?i.setAttribute("href",this.section.canonical):(i=this.document.createElement("link"),i.setAttribute("rel","canonical"),i.setAttribute("href",this.section.canonical),this.document.querySelector("head").appendChild(i)),this.contents.on(M.CONTENTS.EXPAND,()=>{this.displayed&&this.iframe&&(this.expand(),this.contents&&this.layout.format(this.contents))}),this.contents.on(M.CONTENTS.RESIZE,n=>{this.displayed&&this.iframe&&(this.expand(),this.contents&&this.layout.format(this.contents))}),e.resolve(this.contents)}setLayout(t){this.layout=t,this.contents&&(this.layout.format(this.contents),this.expand())}setAxis(t){this.settings.axis=t,t=="horizontal"?this.element.style.flex="none":this.element.style.flex="initial",this.size()}setWritingMode(t){this.writingMode=t}addListeners(){}removeListeners(t){}display(t){const e=new st;return this.displayed?e.resolve(this):this.render(t).then((function(){this.emit(M.VIEWS.DISPLAYED,this),this.onDisplayed(this),this.displayed=!0,e.resolve(this)}).bind(this),function(i){e.reject(i)}),e.promise}show(){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=""),this.emit(M.VIEWS.SHOWN,this)}hide(){this.element.style.visibility="hidden",this.iframe.style.visibility="hidden",this.stopExpanding=!0,this.emit(M.VIEWS.HIDDEN,this)}offset(){return{top:this.element.offsetTop,left:this.element.offsetLeft}}width(){return this._width}height(){return this._height}position(){return this.element.getBoundingClientRect()}locationOf(t){this.iframe.getBoundingClientRect();const e=this.contents.locationOf(t,this.settings.ignoreClass);return{left:e.left,top:e.top}}onDisplayed(t){}onResize(t,e){}bounds(t){return(t||!this.elementBounds)&&(this.elementBounds=Pe(this.element)),this.elementBounds}highlight(t,e={},i,n="epubjs-hl",s={}){if(!this.contents)return;const r=Object.assign({fill:"yellow","fill-opacity":"0.3","mix-blend-mode":"multiply"},s),o=this.contents.range(t),l=()=>{this.emit(M.VIEWS.MARK_CLICKED,t,e)};e.epubcfi=t,this.pane||(this.pane=new Ai(this.iframe,this.element));const f=new Zi(o,n,e,r),m=this.pane.addMark(f);return this.highlights[t]={mark:m,element:m.element,listeners:[l,i]},m.element.setAttribute("ref",n),m.element.addEventListener("click",l),m.element.addEventListener("touchstart",l),i&&(m.element.addEventListener("click",i),m.element.addEventListener("touchstart",i)),m}underline(t,e={},i,n="epubjs-ul",s={}){if(!this.contents)return;const r=Object.assign({stroke:"black","stroke-opacity":"0.3","mix-blend-mode":"multiply"},s),o=this.contents.range(t),l=()=>{this.emit(M.VIEWS.MARK_CLICKED,t,e)};e.epubcfi=t,this.pane||(this.pane=new Ai(this.iframe,this.element));const f=new fs(o,n,e,r),m=this.pane.addMark(f);return this.underlines[t]={mark:m,element:m.element,listeners:[l,i]},m.element.setAttribute("ref",n),m.element.addEventListener("click",l),m.element.addEventListener("touchstart",l),i&&(m.element.addEventListener("click",i),m.element.addEventListener("touchstart",i)),m}mark(t,e={},i){if(!this.contents)return;if(t in this.marks)return this.marks[t];let n=this.contents.range(t);if(!n)return;const s=n.commonAncestorContainer,r=s.nodeType===1?s:s.parentNode,o=f=>{this.emit(M.VIEWS.MARK_CLICKED,t,e)};n.collapsed&&s.nodeType===1?(n=new Range,n.selectNodeContents(s)):n.collapsed&&(n=new Range,n.selectNodeContents(r));const l=this.document.createElement("a");return l.setAttribute("ref","epubjs-mk"),l.style.position="absolute",l.dataset.epubcfi=t,e&&Object.keys(e).forEach(f=>{l.dataset[f]=e[f]}),i&&(l.addEventListener("click",i),l.addEventListener("touchstart",i)),l.addEventListener("click",o),l.addEventListener("touchstart",o),this.placeMark(l,n),this.element.appendChild(l),this.marks[t]={element:l,range:n,listeners:[o,i]},r}placeMark(t,e){let i,n,s;if(this.layout.name==="pre-paginated"||this.settings.axis!=="horizontal"){const r=e.getBoundingClientRect();i=r.top,n=r.right}else{const r=e.getClientRects();let o;for(let l=0;l!=r.length;l++)o=r[l],(!s||o.left<s)&&(s=o.left,n=Math.ceil(s/this.layout.props.pageWidth)*this.layout.props.pageWidth-this.layout.gap/2,i=o.top)}t.style.top=`${i}px`,t.style.left=`${n}px`}unhighlight(t){if(t in this.highlights){const e=this.highlights[t];this.pane.removeMark(e.mark),e.listeners.forEach(i=>{i&&(e.element.removeEventListener("click",i),e.element.removeEventListener("touchstart",i))}),delete this.highlights[t]}}ununderline(t){if(t in this.underlines){const e=this.underlines[t];this.pane.removeMark(e.mark),e.listeners.forEach(i=>{i&&(e.element.removeEventListener("click",i),e.element.removeEventListener("touchstart",i))}),delete this.underlines[t]}}unmark(t){if(t in this.marks){const e=this.marks[t];this.element.removeChild(e.element),e.listeners.forEach(i=>{i&&(e.element.removeEventListener("click",i),e.element.removeEventListener("touchstart",i))}),delete this.marks[t]}}destroy(){for(const t in this.highlights)this.unhighlight(t);for(const t in this.underlines)this.ununderline(t);for(const t in this.marks)this.unmark(t);this.blobUrl&&Fi(this.blobUrl),this.displayed&&(this.displayed=!1,this.removeListeners(),this.contents.destroy(),this.stopExpanding=!0,this.element.removeChild(this.iframe),this.pane&&(this.pane.element.remove(),this.pane=void 0),this.iframe=void 0,this.contents=void 0,this._textWidth=null,this._textHeight=null,this._width=null,this._height=null)}}Wt(Qi.prototype);function ps(){let h="reverse";const t=gs();return document.body.appendChild(t),t.scrollLeft>0?h="default":typeof Element<"u"&&typeof Element.prototype.scrollIntoView=="function"?(t.children[0].children[1].scrollIntoView(),t.scrollLeft<0&&(h="negative")):(t.scrollLeft=1,t.scrollLeft===0&&(h="negative")),document.body.removeChild(t),h}function gs(){const h=document.createElement("div");h.dir="rtl",h.style.position="fixed",h.style.width="1px",h.style.height="1px",h.style.top="0px",h.style.left="0px",h.style.overflow="hidden";const t=document.createElement("div");t.style.width="2px";const e=document.createElement("span");e.style.width="1px",e.style.display="inline-block";const i=document.createElement("span");return i.style.width="1px",i.style.display="inline-block",t.appendChild(e),t.appendChild(i),h.appendChild(t),h}function ms(h,t){let e=null,i=0;return function(){const n=Date.now(),s=t-(n-i);s<=0||s>t?(e&&(clearTimeout(e),e=null),i=n,h.apply(this,arguments)):e||(e=setTimeout(()=>{i=Date.now(),e=null,h.apply(this,arguments)},s))}}class vs{constructor(t){this.settings=t||{},this.id="epubjs-container-"+Xe(),this.container=this.create(this.settings),this.settings.hidden&&(this.wrapper=this.wrap(this.container))}create(t){let e=t.height,i=t.width;const n=t.overflow||!1,s=t.axis||"vertical",r=t.direction;xt(this.settings,t),t.height&&ut(t.height)&&(e=t.height+"px"),t.width&&ut(t.width)&&(i=t.width+"px");const o=document.createElement("div");return o.id=this.id,o.classList.add("epub-container"),o.style.wordSpacing="0",o.style.lineHeight="0",o.style.verticalAlign="top",o.style.position="relative",s==="horizontal"&&(o.style.display="flex",o.style.flexDirection="row",o.style.flexWrap="nowrap"),i&&(o.style.width=i),e&&(o.style.height=e),n&&(n==="scroll"&&s==="vertical"?(o.style.overflowY=n,o.style.overflowX="hidden"):n==="scroll"&&s==="horizontal"?(o.style.overflowY="hidden",o.style.overflowX=n):o.style.overflow=n),r&&(o.dir=r,o.style.direction=r),r&&this.settings.fullsize&&(document.body.style.direction=r),o}wrap(t){const e=document.createElement("div");return e.style.visibility="hidden",e.style.overflow="hidden",e.style.width="0",e.style.height="0",e.appendChild(t),e}getElement(t){let e=null;if(zi(t)?e=t:typeof t=="string"&&(e=document.getElementById(t)),!e)throw new Error("Not an Element");return e}attachTo(t){const e=this.getElement(t);let i;if(e)return this.settings.hidden?i=this.wrapper:i=this.container,e.appendChild(i),this.element=e,e}getContainer(){return this.container}onResize(t){(!ut(this.settings.width)||!ut(this.settings.height))&&(this.resizeFunc=ms(t,50),window.addEventListener("resize",this.resizeFunc,!1))}onOrientationChange(t){this.orientationChangeFunc=t,window.addEventListener("orientationchange",this.orientationChangeFunc,!1)}size(t,e){let i;const n=t||this.settings.width,s=e||this.settings.height;t===null?(i=this.element.getBoundingClientRect(),i.width&&(t=Math.floor(i.width),this.container.style.width=t+"px")):ut(t)?this.container.style.width=t+"px":t&&(this.container.style.width=t),e===null?(i=i||this.element.getBoundingClientRect(),i.height&&(e=i.height,this.container.style.height=e+"px")):ut(e)?this.container.style.height=e+"px":e&&(this.container.style.height=e),ut(t)||(t=this.container.clientWidth),ut(e)||(e=this.container.clientHeight),this.containerStyles=window.getComputedStyle(this.container),this.containerPadding={left:parseFloat(this.containerStyles.paddingLeft)||0,right:parseFloat(this.containerStyles.paddingRight)||0,top:parseFloat(this.containerStyles.paddingTop)||0,bottom:parseFloat(this.containerStyles.paddingBottom)||0};const r=Ue(),o=window.getComputedStyle(document.body),l={left:parseFloat(o.paddingLeft)||0,right:parseFloat(o.paddingRight)||0,top:parseFloat(o.paddingTop)||0,bottom:parseFloat(o.paddingBottom)||0};return n||(t=r.width-l.left-l.right),(this.settings.fullsize&&!s||!s)&&(e=r.height-l.top-l.bottom),{width:t-this.containerPadding.left-this.containerPadding.right,height:e-this.containerPadding.top-this.containerPadding.bottom}}bounds(){let t;return this.container.style.overflow!=="visible"&&(t=this.container&&this.container.getBoundingClientRect()),!t||!t.width||!t.height?Ue():t}getSheet(){const t=document.createElement("style");return t.appendChild(document.createTextNode("")),document.head.appendChild(t),t.sheet}addStyleRules(t,e){const i="#"+this.id+" ";let n="";this.sheet||(this.sheet=this.getSheet()),e.forEach(function(s){for(const r in s)s.hasOwnProperty(r)&&(n+=r+":"+s[r]+";")}),this.sheet.insertRule(i+t+" {"+n+"}",0)}axis(t){t==="horizontal"?(this.container.style.display="flex",this.container.style.flexDirection="row",this.container.style.flexWrap="nowrap"):this.container.style.display="block",this.settings.axis=t}direction(t){this.container&&(this.container.dir=t,this.container.style.direction=t),this.settings.fullsize&&(document.body.style.direction=t),this.settings.dir=t}overflow(t){this.container&&(t==="scroll"&&this.settings.axis==="vertical"?(this.container.style.overflowY=t,this.container.style.overflowX="hidden"):t==="scroll"&&this.settings.axis==="horizontal"?(this.container.style.overflowY="hidden",this.container.style.overflowX=t):this.container.style.overflow=t),this.settings.overflow=t}destroy(){this.element&&(this.settings.hidden?this.wrapper:this.container,this.element.contains(this.container)&&this.element.removeChild(this.container),window.removeEventListener("resize",this.resizeFunc),window.removeEventListener("orientationChange",this.orientationChangeFunc))}}class ys{constructor(t){this.container=t,this._views=[],this.length=0,this.hidden=!1}all(){return this._views}first(){return this._views[0]}last(){return this._views[this._views.length-1]}indexOf(t){return this._views.indexOf(t)}slice(...t){return this._views.slice.apply(this._views,t)}get(t){return this._views[t]}append(t){return this._views.push(t),this.container&&this.container.appendChild(t.element),this.length++,t}prepend(t){return this._views.unshift(t),this.container&&this.container.insertBefore(t.element,this.container.firstChild),this.length++,t}insert(t,e){return this._views.splice(e,0,t),this.container&&(e<this.container.children.length?this.container.insertBefore(t.element,this.container.children[e]):this.container.appendChild(t.element)),this.length++,t}remove(t){const e=this._views.indexOf(t);e>-1&&this._views.splice(e,1),this.destroy(t),this.length--}destroy(t){t.displayed&&t.destroy(),this.container&&this.container.removeChild(t.element)}forEach(t){return this._views.forEach(t)}clear(){let t;const e=this.length;if(this.length){for(let i=0;i<e;i++)t=this._views[i],this.destroy(t);this._views=[],this.length=0}}find(t){let e;const i=this.length;for(let n=0;n<i;n++)if(e=this._views[n],e.displayed&&e.section.index==t.index)return e}displayed(){const t=[];let e;const i=this.length;for(let n=0;n<i;n++)e=this._views[n],e.displayed&&t.push(e);return t}show(){let t;const e=this.length;for(let i=0;i<e;i++)t=this._views[i],t.displayed&&t.show();this.hidden=!1}hide(){let t;const e=this.length;for(let i=0;i<e;i++)t=this._views[i],t.displayed&&t.hide();this.hidden=!0}}class Ve{constructor(t){this.name="default",this.optsSettings=t.settings,this.View=t.view,this.request=t.request,this.renditionQueue=t.queue,this.q=new gi(this),this.settings=xt(this.settings||{},{infinite:!0,hidden:!1,width:void 0,height:void 0,axis:void 0,writingMode:void 0,flow:"scrolled",ignoreClass:"",fullsize:void 0,allowScriptedContent:!1,allowPopups:!1}),xt(this.settings,t.settings||{}),this.viewSettings={ignoreClass:this.settings.ignoreClass,axis:this.settings.axis,flow:this.settings.flow,layout:this.layout,method:this.settings.method,width:0,height:0,forceEvenPages:!0,allowScriptedContent:this.settings.allowScriptedContent,allowPopups:this.settings.allowPopups},this.rendered=!1}render(t,e){const i=t.tagName;typeof this.settings.fullsize>"u"&&i&&(i.toLowerCase()=="body"||i.toLowerCase()=="html")&&(this.settings.fullsize=!0),this.settings.fullsize&&(this.settings.overflow="visible",this.overflow=this.settings.overflow),this.settings.size=e,this.settings.rtlScrollType=ps(),this.stage=new vs({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 ys(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}addEventListeners(){let t;window.addEventListener("unload",(function(e){this.destroy()}).bind(this)),this.settings.fullsize?t=window:t=this.container,this._onScroll=this.onScroll.bind(this),t.addEventListener("scroll",this._onScroll)}removeEventListeners(){let t;this.settings.fullsize?t=window:t=this.container,t.removeEventListener("scroll",this._onScroll),this._onScroll=void 0}destroy(){clearTimeout(this.orientationTimeout),clearTimeout(this.resizeTimeout),clearTimeout(this.afterScrolled),this.clear(),this.removeEventListeners(),this.stage.destroy(),this.rendered=!1}onOrientationChange(t){const{orientation:e}=window;this.optsSettings.resizeOnOrientationChange&&this.resize(),clearTimeout(this.orientationTimeout),this.orientationTimeout=setTimeout((function(){this.orientationTimeout=void 0,this.optsSettings.resizeOnOrientationChange&&this.resize(),this.emit(M.MANAGERS.ORIENTATION_CHANGE,e)}).bind(this),500)}onResized(t){this.resize()}resize(t,e,i){const n=this.stage.size(t,e);if(this.winBounds=Ue(),this.orientationTimeout&&this.winBounds.width===this.winBounds.height){this._stageSize=void 0;return}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(M.MANAGERS.RESIZED,{width:this._stageSize.width,height:this._stageSize.height},i))}createView(t,e){return new this.View(t,xt(this.viewSettings,{forceRight:e}))}handleNextPrePaginated(t,e,i){let n;if(this.layout.name==="pre-paginated"&&this.layout.divisor>1){if(t||e.index===0)return;if(n=e.next(),n&&!n.properties.includes("page-spread-left"))return i.call(this,n)}}display(t,e){const i=new st,n=i.promise;(e===t.href||ut(e))&&(e=void 0);const s=this.views.find(t);if(s&&t&&this.layout.name!=="pre-paginated"){const o=s.offset();if(this.settings.direction==="ltr")this.scrollTo(o.left,o.top,!0);else{const l=s.width();this.scrollTo(o.left+l,o.top,!0)}if(e){const l=s.locationOf(e),f=s.width();this.moveTo(l,f)}return i.resolve(),n}this.clear();let r=!1;return this.layout.name==="pre-paginated"&&this.layout.divisor===2&&t.properties.includes("page-spread-right")&&(r=!0),this.add(t,r).then((function(o){if(e){const l=o.locationOf(e),f=o.width();this.moveTo(l,f)}}).bind(this),o=>{i.reject(o)}).then((function(){return this.handleNextPrePaginated(r,t,this.add)}).bind(this)).then((function(){this.views.show(),i.resolve()}).bind(this)),n}afterDisplayed(t){this.emit(M.MANAGERS.ADDED,t)}afterResized(t){this.emit(M.MANAGERS.RESIZE,t.section)}moveTo(t,e){let i=0,n=0;this.isPaginated?(i=Math.floor(t.left/this.layout.delta)*this.layout.delta,i+this.layout.delta>this.container.scrollWidth&&(i=this.container.scrollWidth-this.layout.delta),n=Math.floor(t.top/this.layout.delta)*this.layout.delta,n+this.layout.delta>this.container.scrollHeight&&(n=this.container.scrollHeight-this.layout.delta)):n=t.top,this.settings.direction==="rtl"&&(i=i+this.layout.delta,i=i-e),this.scrollTo(i,n,!0)}add(t,e){const i=this.createView(t,e);return this.views.append(i),i.onDisplayed=this.afterDisplayed.bind(this),i.onResize=this.afterResized.bind(this),i.on(M.VIEWS.AXIS,n=>{this.updateAxis(n)}),i.on(M.VIEWS.WRITING_MODE,n=>{this.updateWritingMode(n)}),i.display(this.request)}append(t,e){const i=this.createView(t,e);return this.views.append(i),i.onDisplayed=this.afterDisplayed.bind(this),i.onResize=this.afterResized.bind(this),i.on(M.VIEWS.AXIS,n=>{this.updateAxis(n)}),i.on(M.VIEWS.WRITING_MODE,n=>{this.updateWritingMode(n)}),i.display(this.request)}prepend(t,e){const i=this.createView(t,e);return i.on(M.VIEWS.RESIZED,n=>{this.counter(n)}),this.views.prepend(i),i.onDisplayed=this.afterDisplayed.bind(this),i.onResize=this.afterResized.bind(this),i.on(M.VIEWS.AXIS,n=>{this.updateAxis(n)}),i.on(M.VIEWS.WRITING_MODE,n=>{this.updateWritingMode(n)}),i.display(this.request)}counter(t){this.settings.axis==="vertical"?this.scrollBy(0,t.heightDelta,!0):this.scrollBy(t.widthDelta,0,!0)}next(){let t,e;const i=this.settings.direction;if(this.views.length&&(this.isPaginated&&this.settings.axis==="horizontal"&&(!i||i==="ltr")?(this.scrollLeft=this.container.scrollLeft,e=this.container.scrollLeft+this.container.offsetWidth+this.layout.delta,e<=this.container.scrollWidth?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next()):this.isPaginated&&this.settings.axis==="horizontal"&&i==="rtl"?(this.scrollLeft=this.container.scrollLeft,this.settings.rtlScrollType==="default"?(e=this.container.scrollLeft,e>0?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next()):(e=this.container.scrollLeft+this.layout.delta*-1,e>this.container.scrollWidth*-1?this.scrollBy(this.layout.delta,0,!0):t=this.views.last().section.next())):this.isPaginated&&this.settings.axis==="vertical"?(this.scrollTop=this.container.scrollTop,this.container.scrollTop+this.container.offsetHeight<this.container.scrollHeight?this.scrollBy(0,this.layout.height,!0):t=this.views.last().section.next()):t=this.views.last().section.next(),t)){this.clear(),this.updateLayout();let n=!1;return this.layout.name==="pre-paginated"&&this.layout.divisor===2&&t.properties.includes("page-spread-right")&&(n=!0),this.append(t,n).then((function(){return this.handleNextPrePaginated(n,t,this.append)}).bind(this),s=>s).then((function(){!this.isPaginated&&this.settings.axis==="horizontal"&&this.settings.direction==="rtl"&&this.settings.rtlScrollType==="default"&&this.scrollTo(this.container.scrollWidth,0,!0),this.views.show()}).bind(this))}}prev(){let t,e;const i=this.settings.direction;if(this.views.length&&(this.isPaginated&&this.settings.axis==="horizontal"&&(!i||i==="ltr")?(this.scrollLeft=this.container.scrollLeft,e=this.container.scrollLeft,e>0?this.scrollBy(-this.layout.delta,0,!0):t=this.views.first().section.prev()):this.isPaginated&&this.settings.axis==="horizontal"&&i==="rtl"?(this.scrollLeft=this.container.scrollLeft,this.settings.rtlScrollType==="default"?(e=this.container.scrollLeft+this.container.offsetWidth,e<this.container.scrollWidth?this.scrollBy(-this.layout.delta,0,!0):t=this.views.first().section.prev()):(e=this.container.scrollLeft,e<0?this.scrollBy(-this.layout.delta,0,!0):t=this.views.first().section.prev())):this.isPaginated&&this.settings.axis==="vertical"?(this.scrollTop=this.container.scrollTop,this.container.scrollTop>0?this.scrollBy(0,-this.layout.height,!0):t=this.views.first().section.prev()):t=this.views.first().section.prev(),t)){this.clear(),this.updateLayout();let n=!1;return this.layout.name==="pre-paginated"&&this.layout.divisor===2&&typeof t.prev()!="object"&&(n=!0),this.prepend(t,n).then((function(){let s;if(this.layout.name==="pre-paginated"&&this.layout.divisor>1&&(s=t.prev(),s))return this.prepend(s)}).bind(this),s=>s).then((function(){this.isPaginated&&this.settings.axis==="horizontal"&&(this.settings.direction==="rtl"?this.settings.rtlScrollType==="default"?this.scrollTo(0,0,!0):this.scrollTo(this.container.scrollWidth*-1+this.layout.delta,0,!0):this.scrollTo(this.container.scrollWidth-this.layout.delta,0,!0)),this.views.show()}).bind(this))}}current(){const t=this.visible();return t.length?t[t.length-1]:null}clear(){this.views&&(this.views.hide(),this.scrollTo(0,0,!0),this.views.clear())}currentLocation(){return this.updateLayout(),this.isPaginated&&this.settings.axis==="horizontal"?this.location=this.paginatedLocation():this.location=this.scrolledLocation(),this.location}scrolledLocation(){const t=this.visible(),e=this.container.getBoundingClientRect(),i=e.height<window.innerHeight?e.height:window.innerHeight,n=e.width<window.innerWidth?e.width:window.innerWidth,s=this.settings.axis==="vertical";this.settings.direction;let r=0;const o=0;return this.settings.fullsize&&(r=s?window.scrollY:window.scrollX),t.map(f=>{const{index:m,href:b}=f.section,E=f.position(),N=f.width(),W=f.height();let T,D,q,U;s?(T=r+e.top-E.top+o,D=T+i-o,U=this.layout.count(W,i).pages,q=i):(T=r+e.left-E.left+o,D=T+n-o,U=this.layout.count(N,n).pages,q=n);let $=Math.ceil(T/q),X=[],R=Math.ceil(D/q);if(this.settings.direction==="rtl"&&!s){const P=$;$=U-R,R=U-P}X=[];for(let P=$;P<=R;P++){const Y=P+1;X.push(Y)}const z=this.mapping.page(f.contents,f.section.cfiBase,T,D);return{index:m,href:b,pages:X,totalPages:U,mapping:z}})}paginatedLocation(){const t=this.visible(),e=this.container.getBoundingClientRect();let i=0,n=0;return this.settings.fullsize&&(i=window.scrollX),t.map(r=>{const{index:o,href:l}=r.section;let f;const m=r.position(),b=r.width();let E,N,W;this.settings.direction==="rtl"?(f=e.right-i,W=Math.min(Math.abs(f-m.left),this.layout.width)-n,N=m.width-(m.right-f)-n,E=N-W):(f=e.left+i,W=Math.min(m.right-f,this.layout.width)-n,E=f-m.left+n,N=E+W),n+=W;const T=this.mapping.page(r.contents,r.section.cfiBase,E,N),D=this.layout.count(b).pages;let q=Math.floor(E/this.layout.pageWidth);const U=[];let $=Math.floor(N/this.layout.pageWidth);if(q<0&&(q=0,$=$+1),this.settings.direction==="rtl"){const X=q;q=D-$,$=D-X}for(let X=q+1;X<=$;X++){const R=X;U.push(R)}return{index:o,href:l,pages:U,totalPages:D,mapping:T}})}isVisible(t,e,i,n){const s=t.position(),r=n||this.bounds();return this.settings.axis==="horizontal"&&s.right>r.left-e&&s.left<r.right+i?!0:this.settings.axis==="vertical"&&s.bottom>r.top-e&&s.top<r.bottom+i}visible(){const t=this.bounds(),e=this.views.displayed(),i=e.length,n=[];let s,r;for(let o=0;o<i;o++)r=e[o],s=this.isVisible(r,0,0,t),s===!0&&n.push(r);return n}scrollBy(t,e,i){const n=this.settings.direction==="rtl"?-1:1;i&&(this.ignore=!0),this.settings.fullsize?window.scrollBy(t*n,e*n):(t&&(this.container.scrollLeft+=t*n),e&&(this.container.scrollTop+=e)),this._hasScrolled=!0}scrollTo(t,e,i){i&&(this.ignore=!0),this.settings.fullsize?window.scrollTo(t,e):(this.container.scrollLeft=t,this.container.scrollTop=e),this._hasScrolled=!0}onScroll(){let t,e;this.settings.fullsize?(t=window.scrollY,e=window.scrollX):(t=this.container.scrollTop,e=this.container.scrollLeft),this.scrollTop=t,this.scrollLeft=e,this.ignore?this.ignore=!1:(this.emit(M.MANAGERS.SCROLL,{top:t,left:e}),clearTimeout(this.afterScrolled),this.afterScrolled=setTimeout((function(){this.emit(M.MANAGERS.SCROLLED,{top:this.scrollTop,left:this.scrollLeft})}).bind(this),20))}bounds(){return this.stage.bounds()}applyLayout(t){this.layout=t,this.updateLayout(),this.views&&this.views.length>0&&this.layout.name==="pre-paginated"&&this.display(this.views.first().section)}updateLayout(){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))}setLayout(t){this.viewSettings.layout=t,this.mapping=new je(t.props,this.settings.direction,this.settings.axis),this.views&&this.views.forEach(function(e){e&&e.setLayout(t)})}updateWritingMode(t){this.writingMode=t}updateAxis(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 je(this.layout.props,this.settings.direction,this.settings.axis)),this.layout&&(t==="vertical"?this.layout.spread("none"):this.layout.spread(this.layout.settings.spread)))}updateFlow(t,e="auto"){const i=t==="paginated"||t==="auto";this.isPaginated=i,t==="scrolled-doc"||t==="scrolled-continuous"||t==="scrolled"?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()}getContents(){const t=[];return this.views&&this.views.forEach(function(e){const i=e&&e.contents;i&&t.push(i)}),t}direction(t="ltr"){this.settings.direction=t,this.stage&&this.stage.direction(t),this.viewSettings.direction=t,this.updateLayout()}isRendered(){return this.rendered}}Wt(Ve.prototype);const ws={easeInCubic:function(h){return Math.pow(h,3)}};class ui{constructor(t,e){this.settings=xt({duration:80,minVelocity:.2,minDistance:10,easing:ws.easeInCubic},e||{}),this.supportsTouch=this.supportsTouch(),this.supportsTouch&&this.setup(t)}setup(t){this.manager=t,this.layout=this.manager.layout,this.fullsize=this.manager.settings.fullsize??!1,this.fullsize?(this.element=this.manager.stage.element,this.scroller=window,this.disableScroll()):(this.element=this.manager.stage.container,this.scroller=this.element,this.element.style.WebkitOverflowScrolling="touch"),this.manager.settings.offset=this.layout.width,this.manager.settings.afterScrolledTimeout=this.settings.duration*2,this.isVertical=this.manager.settings.axis==="vertical",!(!this.manager.isPaginated||this.isVertical)&&(this.touchCanceler=!1,this.resizeCanceler=!1,this.snapping=!1,this.scrollLeft,this.scrollTop,this.startTouchX=void 0,this.startTouchY=void 0,this.startTime=void 0,this.endTouchX=void 0,this.endTouchY=void 0,this.endTime=void 0,this.addListeners())}supportsTouch(){return!!("ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch)}disableScroll(){this.element.style.overflow="hidden"}enableScroll(){this.element.style.overflow=""}addListeners(){this._onResize=this.onResize.bind(this),window.addEventListener("resize",this._onResize),this._onScroll=this.onScroll.bind(this),this.scroller.addEventListener("scroll",this._onScroll),this._onTouchStart=this.onTouchStart.bind(this),this.scroller.addEventListener("touchstart",this._onTouchStart,{passive:!0}),this.on("touchstart",this._onTouchStart),this._onTouchMove=this.onTouchMove.bind(this),this.scroller.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.on("touchmove",this._onTouchMove),this._onTouchEnd=this.onTouchEnd.bind(this),this.scroller.addEventListener("touchend",this._onTouchEnd,{passive:!0}),this.on("touchend",this._onTouchEnd),this._afterDisplayed=this.afterDisplayed.bind(this),this.manager.on(M.MANAGERS.ADDED,this._afterDisplayed)}removeListeners(){window.removeEventListener("resize",this._onResize),this._onResize=void 0,this.scroller.removeEventListener("scroll",this._onScroll),this._onScroll=void 0,this.scroller.removeEventListener("touchstart",this._onTouchStart,{passive:!0}),this.off("touchstart",this._onTouchStart),this._onTouchStart=void 0,this.scroller.removeEventListener("touchmove",this._onTouchMove,{passive:!0}),this.off("touchmove",this._onTouchMove),this._onTouchMove=void 0,this.scroller.removeEventListener("touchend",this._onTouchEnd,{passive:!0}),this.off("touchend",this._onTouchEnd),this._onTouchEnd=void 0,this.manager.off(M.MANAGERS.ADDED,this._afterDisplayed),this._afterDisplayed=void 0}afterDisplayed(t){const e=t.contents;["touchstart","touchmove","touchend"].forEach(i=>{e.on(i,n=>this.triggerViewEvent(n,e))})}triggerViewEvent(t,e){this.emit(t.type,t,e)}onScroll(t){this.scrollLeft=this.fullsize?window.scrollX:this.scroller.scrollLeft,this.scrollTop=this.fullsize?window.scrollY:this.scroller.scrollTop}onResize(t){this.resizeCanceler=!0}onTouchStart(t){const{screenX:e,screenY:i}=t.touches[0];this.fullsize&&this.enableScroll(),this.touchCanceler=!0,this.startTouchX||(this.startTouchX=e,this.startTouchY=i,this.startTime=this.now()),this.endTouchX=e,this.endTouchY=i,this.endTime=this.now()}onTouchMove(t){const{screenX:e,screenY:i}=t.touches[0],n=Math.abs(i-this.endTouchY);this.touchCanceler=!0,!this.fullsize&&n<10&&(this.element.scrollLeft-=e-this.endTouchX),this.endTouchX=e,this.endTouchY=i,this.endTime=this.now()}onTouchEnd(t){this.fullsize&&this.disableScroll(),this.touchCanceler=!1;const e=this.wasSwiped();e!==0?this.snap(e):this.snap(),this.startTouchX=void 0,this.startTouchY=void 0,this.startTime=void 0,this.endTouchX=void 0,this.endTouchY=void 0,this.endTime=void 0}wasSwiped(){const t=this.layout.pageWidth*this.layout.divisor,e=this.endTouchX-this.startTouchX,i=Math.abs(e),n=this.endTime-this.startTime,s=e/n,r=this.settings.minVelocity;return i<=this.settings.minDistance||i>=t?0:s>r?-1:s<-r?1:0}needsSnap(){const t=this.scrollLeft,e=this.layout.pageWidth*this.layout.divisor;return t%e!==0}snap(t=0){const e=this.scrollLeft,i=this.layout.pageWidth*this.layout.divisor;let n=Math.round(e/i)*i;return t&&(n+=t*i),this.smoothScrollTo(n)}smoothScrollTo(t){const e=new st,i=this.scrollLeft,n=this.now(),s=this.settings.duration,r=this.settings.easing;this.snapping=!0;function o(){const l=this.now(),f=Math.min(1,(l-n)/s);if(r(f),this.touchCanceler||this.resizeCanceler){this.resizeCanceler=!1,this.snapping=!1,e.resolve();return}f<1?(window.requestAnimationFrame(o.bind(this)),this.scrollTo(i+(t-i)*f,0)):(this.scrollTo(t,0),this.snapping=!1,e.resolve())}return o.call(this),e.promise}scrollTo(t=0,e=0){this.fullsize?window.scroll(t,e):(this.scroller.scrollLeft=t,this.scroller.scrollTop=e)}now(){return"now"in window.performance?performance.now():new Date().getTime()}destroy(){this.scroller&&(this.fullsize&&this.enableScroll(),this.removeListeners(),this.scroller=void 0)}}Wt(ui.prototype);function bs(h,t){let e;return function(){const i=this,n=arguments;clearTimeout(e),e=setTimeout(function(){h.apply(i,n)},t)}}class Es extends Ve{constructor(t){super(t),this.name="continuous",this.settings=xt(this.settings||{},{infinite:!0,overflow:void 0,axis:void 0,writingMode:void 0,flow:"scrolled",offset:500,offsetDelta:250,width:void 0,height:void 0,snap:!1,afterScrolledTimeout:10,allowScriptedContent:!1,allowPopups:!1}),xt(this.settings,t.settings||{}),t.settings.gap!="undefined"&&t.settings.gap===0&&(this.settings.gap=t.settings.gap),this.viewSettings={ignoreClass:this.settings.ignoreClass,axis:this.settings.axis,flow:this.settings.flow,layout:this.layout,width:0,height:0,forceEvenPages:!1,allowScriptedContent:this.settings.allowScriptedContent,allowPopups:this.settings.allowPopups},this.scrollTop=0,this.scrollLeft=0}display(t,e){return Ve.prototype.display.call(this,t,e).then((function(){return this.fill()}).bind(this))}fill(t){const e=t||new st;return this.q.enqueue(()=>this.check()).then(i=>{i?this.fill(e):e.resolve()}),e.promise}moveTo(t){let e=0,i=0;this.isPaginated?(e=Math.floor(t.left/this.layout.delta)*this.layout.delta,e+this.settings.offsetDelta):(i=t.top,t.top+this.settings.offsetDelta),(e>0||i>0)&&this.scrollBy(e,i,!0)}afterResized(t){this.emit(M.MANAGERS.RESIZE,t.section)}removeShownListeners(t){t.onDisplayed=function(){}}add(t){const e=this.createView(t);return this.views.append(e),e.on(M.VIEWS.RESIZED,i=>{e.expanded=!0}),e.on(M.VIEWS.AXIS,i=>{this.updateAxis(i)}),e.on(M.VIEWS.WRITING_MODE,i=>{this.updateWritingMode(i)}),e.onDisplayed=this.afterDisplayed.bind(this),e.onResize=this.afterResized.bind(this),e.display(this.request)}append(t){const e=this.createView(t);return e.on(M.VIEWS.RESIZED,i=>{e.expanded=!0}),e.on(M.VIEWS.AXIS,i=>{this.updateAxis(i)}),e.on(M.VIEWS.WRITING_MODE,i=>{this.updateWritingMode(i)}),this.views.append(e),e.onDisplayed=this.afterDisplayed.bind(this),e}prepend(t){const e=this.createView(t);return e.on(M.VIEWS.RESIZED,i=>{this.counter(i),e.expanded=!0}),e.on(M.VIEWS.AXIS,i=>{this.updateAxis(i)}),e.on(M.VIEWS.WRITING_MODE,i=>{this.updateWritingMode(i)}),this.views.prepend(e),e.onDisplayed=this.afterDisplayed.bind(this),e}counter(t){this.settings.axis==="vertical"?this.scrollBy(0,t.heightDelta,!0):this.scrollBy(t.widthDelta,0,!0)}update(t){const e=this.bounds(),i=this.views.all(),n=i.length,s=typeof t<"u"?t:this.settings.offset||0;let r,o;const l=new st,f=[];for(let m=0;m<n;m++)if(o=i[m],r=this.isVisible(o,s,s,e),r===!0)if(o.displayed)o.show();else{const b=o.display(this.request).then(function(E){E.show()},E=>{o.hide()});f.push(b)}else this.q.enqueue(o.destroy.bind(o)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout((function(){this.q.enqueue(this.trim.bind(this))}).bind(this),250);return f.length?Promise.all(f).catch(m=>{l.reject(m)}):(l.resolve(),l.promise)}check(t,e){const i=new st,n=[],s=this.settings.axis==="horizontal";let r=this.settings.offset||0;t&&s&&(r=t),e&&!s&&(r=e);const o=this._bounds;let l=s?this.scrollLeft:this.scrollTop;const f=s?Math.floor(o.width):o.height,m=s?this.container.scrollWidth:this.container.scrollHeight,b=this.writingMode&&this.writingMode.indexOf("vertical")===0?"vertical":"horizontal",E=this.settings.rtlScrollType,N=this.settings.direction==="rtl";this.settings.fullsize?(s&&N&&E==="negative"||!s&&N&&E==="default")&&(l=l*-1):(N&&E==="default"&&b==="horizontal"&&(l=m-f-l),N&&E==="negative"&&b==="horizontal"&&(l=l*-1));const W=()=>{const $=this.views.first(),X=$&&$.section.prev();X&&n.push(this.prepend(X))},T=()=>{const $=this.views.last(),X=$&&$.section.next();X&&n.push(this.append(X))},D=l+f+r,q=l-r;D>=m&&T(),q<0&&W();const U=n.map($=>$.display(this.request));return n.length?Promise.all(U).then(()=>this.check()).then(()=>this.update(r),$=>$):(this.q.enqueue((function(){this.update()}).bind(this)),i.resolve(!1),i.promise)}trim(){const t=new st,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),l=this.views.slice(r+1);for(let f=0;f<o.length-1;f++)this.erase(o[f],o);for(let f=1;f<l.length;f++)this.erase(l[f]);return t.resolve(),t.promise}erase(t,e){let i,n;this.settings.fullsize?(i=window.scrollY,n=window.scrollX):(i=this.container.scrollTop,n=this.container.scrollLeft);const s=t.bounds();this.views.remove(t),e&&(this.settings.axis==="vertical"?this.scrollTo(0,i-s.height,!0):this.settings.direction==="rtl"?this.settings.fullsize?this.scrollTo(n+Math.floor(s.width),0,!0):this.scrollTo(n,0,!0):this.scrollTo(n-Math.floor(s.width),0,!0))}addEventListeners(t){window.addEventListener("unload",(function(e){this.ignore=!0,this.destroy()}).bind(this)),this.addScrollListeners(),this.isPaginated&&this.settings.snap&&(this.snapper=new ui(this,typeof this.settings.snap=="object"?this.settings.snap:void 0))}addScrollListeners(){let t;this.tick=di;const e=this.settings.direction==="rtl"&&this.settings.rtlScrollType==="default"?-1:1;this.scrollDeltaVert=0,this.scrollDeltaHorz=0,this.settings.fullsize?(t=window,this.scrollTop=window.scrollY*e,this.scrollLeft=window.scrollX*e):(t=this.container,this.scrollTop=this.container.scrollTop,this.scrollLeft=this.container.scrollLeft),this._onScroll=this.onScroll.bind(this),t.addEventListener("scroll",this._onScroll),this._scrolled=bs(this.scrolled.bind(this),30),this.didScroll=!1}removeEventListeners(){let t;this.settings.fullsize?t=window:t=this.container,t.removeEventListener("scroll",this._onScroll),this._onScroll=void 0}onScroll(){let t,e;const i=this.settings.direction==="rtl"&&this.settings.rtlScrollType==="default"?-1:1;this.settings.fullsize?(t=window.scrollY*i,e=window.scrollX*i):(t=this.container.scrollTop,e=this.container.scrollLeft),this.scrollTop=t,this.scrollLeft=e,this.ignore?this.ignore=!1:this._scrolled(),this.scrollDeltaVert+=Math.abs(t-this.prevScrollTop),this.scrollDeltaHorz+=Math.abs(e-this.prevScrollLeft),this.prevScrollTop=t,this.prevScrollLeft=e,clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout((function(){this.scrollDeltaVert=0,this.scrollDeltaHorz=0}).bind(this),150),clearTimeout(this.afterScrolled),this.didScroll=!1}scrolled(){this.q.enqueue((function(){return this.check()}).bind(this)),this.emit(M.MANAGERS.SCROLL,{top:this.scrollTop,left:this.scrollLeft}),clearTimeout(this.afterScrolled),this.afterScrolled=setTimeout((function(){this.snapper&&this.snapper.supportsTouch&&this.snapper.needsSnap()||this.emit(M.MANAGERS.SCROLLED,{top:this.scrollTop,left:this.scrollLeft})}).bind(this),this.settings.afterScrolledTimeout)}next(){const t=this.layout.props.name==="pre-paginated"&&this.layout.props.spread?this.layout.props.delta*2:this.layout.props.delta;this.views.length&&(this.isPaginated&&this.settings.axis==="horizontal"?this.scrollBy(t,0,!0):this.scrollBy(0,this.layout.height,!0),this.q.enqueue((function(){return this.check()}).bind(this)))}prev(){const t=this.layout.props.name==="pre-paginated"&&this.layout.props.spread?this.layout.props.delta*2:this.layout.props.delta;this.views.length&&(this.isPaginated&&this.settings.axis==="horizontal"?this.scrollBy(-t,0,!0):this.scrollBy(0,-this.layout.height,!0),this.q.enqueue((function(){return this.check()}).bind(this)))}updateFlow(t){this.rendered&&this.snapper&&(this.snapper.destroy(),this.snapper=void 0),super.updateFlow(t,"scroll"),this.rendered&&this.isPaginated&&this.settings.snap&&(this.snapper=new ui(this,typeof this.settings.snap=="object"?this.settings.snap:void 0))}destroy(){super.destroy(),this.snapper&&this.snapper.destroy()}}class Ge{constructor(t,e){this.settings=xt(this.settings||{},{width:null,height:null,ignoreClass:"",manager:"default",view:"iframe",flow:null,layout:null,spread:null,minSpreadWidth:800,stylesheet:null,resizeOnOrientationChange:!0,script:null,snap:!1,defaultDirection:"ltr",allowScriptedContent:!1,allowPopups:!1}),xt(this.settings,e),typeof this.settings.manager=="object"&&(this.manager=this.settings.manager),this.book=t,this.hooks={},this.hooks.display=new Mt(this),this.hooks.serialize=new Mt(this),this.hooks.content=new Mt(this),this.hooks.unloaded=new Mt(this),this.hooks.layout=new Mt(this),this.hooks.render=new Mt(this),this.hooks.show=new Mt(this),this.hooks.content.register(this.handleLinks.bind(this)),this.hooks.content.register(this.passEvents.bind(this)),this.hooks.content.register(this.adjustImages.bind(this)),this.book.spine.hooks.content.register(this.injectIdentifier.bind(this)),this.settings.stylesheet&&this.book.spine.hooks.content.register(this.injectStylesheet.bind(this)),this.settings.script&&this.book.spine.hooks.content.register(this.injectScript.bind(this)),this.themes=new is(this),this.annotations=new ns(this),this.epubcfi=new et,this.q=new gi(this),this.location=void 0,this.q.enqueue(this.book.opened),this.starting=new st,this.started=this.starting.promise,this.q.enqueue(this.start)}setManager(t){this.manager=t}requireManager(t){let e;return typeof t=="string"&&t==="default"?e=Ve:typeof t=="string"&&t==="continuous"?e=Es:e=t,e}requireView(t){let e;return typeof t=="string"&&t==="iframe"?e=Qi:e=t,e}start(){switch(!this.settings.layout&&(this.book.package.metadata.layout==="pre-paginated"||this.book.displayOptions.fixedLayout==="true")&&(this.settings.layout="pre-paginated"),this.book.package.metadata.spread){case"none":this.settings.spread="none";break;case"both":this.settings.spread=!0;break}this.manager||(this.ViewManager=this.requireManager(this.settings.manager),this.View=this.requireView(this.settings.view),this.manager=new this.ViewManager({view:this.View,queue:this.q,request:this.book.load.bind(this.book),settings:this.settings})),this.direction(this.book.package.metadata.direction||this.settings.defaultDirection),this.settings.globalLayoutProperties=this.determineLayoutProperties(this.book.package.metadata),this.flow(this.settings.globalLayoutProperties.flow),this.layout(this.settings.globalLayoutProperties),this.manager.on(M.MANAGERS.ADDED,this.afterDisplayed.bind(this)),this.manager.on(M.MANAGERS.REMOVED,this.afterRemoved.bind(this)),this.manager.on(M.MANAGERS.RESIZED,this.onResized.bind(this)),this.manager.on(M.MANAGERS.ORIENTATION_CHANGE,this.onOrientationChange.bind(this)),this.manager.on(M.MANAGERS.SCROLLED,this.reportLocation.bind(this)),this.emit(M.RENDITION.STARTED),this.starting.resolve()}attachTo(t){return this.q.enqueue((function(){this.manager.render(t,{width:this.settings.width,height:this.settings.height}),this.emit(M.RENDITION.ATTACHED)}).bind(this))}display(t){return this.displaying&&this.displaying.resolve(),this.q.enqueue(this._display,t)}_display(t){if(!this.book)return;this.epubcfi.isCfiString(t);const e=new st,i=e.promise;this.displaying=e,this.book.locations.length()&&Bi(t)&&(t=this.book.locations.cfiFromPercentage(parseFloat(t)));const n=this.book.spine.get(t);return n?(this.manager.display(n,t).then(()=>{e.resolve(n),this.displaying=void 0,this.emit(M.RENDITION.DISPLAYED,n),this.reportLocation()},s=>{this.emit(M.RENDITION.DISPLAY_ERROR,s)}),i):(e.reject(new Error("No Section Found")),i)}afterDisplayed(t){t.on(M.VIEWS.MARK_CLICKED,(e,i)=>this.triggerMarkEvent(e,i,t.contents)),this.hooks.render.trigger(t,this).then(()=>{t.contents?this.hooks.content.trigger(t.contents,this).then(()=>{this.emit(M.RENDITION.RENDERED,t.section,t)}):this.emit(M.RENDITION.RENDERED,t.section,t)})}afterRemoved(t){this.hooks.unloaded.trigger(t,this).then(()=>{this.emit(M.RENDITION.REMOVED,t.section,t)})}onResized(t,e){this.emit(M.RENDITION.RESIZED,{width:t.width,height:t.height},e),this.location&&this.location.start&&this.display(e||this.location.start.cfi)}onOrientationChange(t){this.emit(M.RENDITION.ORIENTATION_CHANGE,t)}moveTo(t){this.manager.moveTo(t)}resize(t,e,i){t&&(this.settings.width=t),e&&(this.settings.height=e),this.manager.resize(t,e,i)}clear(){this.manager.clear()}next(){return this.q.enqueue(this.manager.next.bind(this.manager)).then(this.reportLocation.bind(this))}prev(){return this.q.enqueue(this.manager.prev.bind(this.manager)).then(this.reportLocation.bind(this))}determineLayoutProperties(t){const e=this.settings.layout||t.layout||"reflowable",i=this.settings.spread||t.spread||"auto",n=this.settings.orientation||t.orientation||"auto",s=this.settings.flow||t.flow||"auto",r=t.viewport||"",o=this.settings.minSpreadWidth||t.minSpreadWidth||800,l=this.settings.direction||t.direction||"ltr";return(this.settings.width===0||this.settings.width>0)&&(this.settings.height===0||this.settings.height>0),{layout:e,spread:i,orientation:n,flow:s,viewport:r,minSpreadWidth:o,direction:l}}flow(t){let e=t;(t==="scrolled"||t==="scrolled-doc"||t==="scrolled-continuous")&&(e="scrolled"),(t==="auto"||t==="paginated")&&(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))}layout(t){return t&&(this._layout=new mi(t),this._layout.spread(t.spread,this.settings.minSpreadWidth),this._layout.on(M.LAYOUT.UPDATED,(e,i)=>{this.emit(M.RENDITION.LAYOUT,e,i)})),this.manager&&this._layout&&this.manager.applyLayout(this._layout),this._layout}spread(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()}direction(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))}reportLocation(){return this.q.enqueue((function(){requestAnimationFrame((function(){const i=this.manager.currentLocation();if(i&&i.then&&typeof i.then=="function")i.then((function(n){const s=this.located(n);!s||!s.start||!s.end||(this.location=s,this.emit(M.RENDITION.LOCATION_CHANGED,{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(M.RENDITION.RELOCATED,this.location))}).bind(this));else if(i){const n=this.located(i);if(!n||!n.start||!n.end)return;this.location=n,this.emit(M.RENDITION.LOCATION_CHANGED,{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(M.RENDITION.RELOCATED,this.location)}}).bind(this))}).bind(this))}currentLocation(){const t=this.manager.currentLocation();if(t&&t.then&&typeof t.then=="function")t.then((function(e){return this.located(e)}).bind(this));else if(t)return this.located(t)}located(t){if(!t.length)return;const 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);s!=null&&(n.start.location=s,n.start.percentage=this.book.locations.percentageFromLocation(s)),r!=null&&(n.end.location=r,n.end.percentage=this.book.locations.percentageFromLocation(r));const o=this.book.pageList.pageFromCfi(e.mapping.start),l=this.book.pageList.pageFromCfi(i.mapping.end);return o!=-1&&(n.start.page=o),l!=-1&&(n.end.page=l),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&&n.start.displayed.page===1&&(n.atStart=!0),n}destroy(){this.manager&&this.manager.destroy(),this.book=void 0}passEvents(t){Me.forEach(e=>{t.on(e,i=>this.triggerViewEvent(i,t))}),t.on(M.CONTENTS.SELECTED,e=>this.triggerSelectedEvent(e,t))}triggerViewEvent(t,e){this.emit(t.type,t,e)}triggerSelectedEvent(t,e){this.emit(M.RENDITION.SELECTED,t,e)}triggerMarkEvent(t,e,i){this.emit(M.RENDITION.MARK_CLICKED,t,e,i)}getRange(t,e){const i=new et(t),n=this.manager.visible().filter(function(s){if(i.spinePos===s.index)return!0});if(n.length)return n[0].contents.range(i,e)}adjustImages(t){if(this._layout.name==="pre-paginated")return new Promise(function(s){s()});const e=t.window.getComputedStyle(t.content,null),i=(t.content.offsetHeight-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)))*.95,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(s,r){setTimeout(function(){s()},1)})}getContents(){return this.manager?this.manager.getContents():[]}views(){return(this.manager?this.manager.views:void 0)||[]}handleLinks(t){t&&t.on(M.CONTENTS.LINK_CLICKED,e=>{const i=this.book.path.relative(e);this.display(i)})}injectStylesheet(t,e){const 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)}injectScript(t,e){const i=t.createElement("script");i.setAttribute("type","text/javascript"),i.setAttribute("src",this.settings.script),i.textContent=" ",t.getElementsByTagName("head")[0].appendChild(i)}injectIdentifier(t,e){const 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)}}Wt(Ge.prototype);class xs{constructor(){this.zip=void 0,this.urlCache={},this.checkRequirements()}checkRequirements(){try{this.zip=new Cn}catch{throw new Error("JSZip lib not loaded")}}open(t,e){return this.zip.loadAsync(t,{base64:e})}openUrl(t,e){return Ce(t,"binary").then((function(i){return this.zip.loadAsync(i,{base64:e})}).bind(this))}request(t,e){const i=new st;let n;const s=new Zt(t);return e||(e=s.extension),e=="blob"?n=this.getBlob(t):n=this.getText(t),n?n.then((function(r){const o=this.handleResponse(r,e);i.resolve(o)}).bind(this)):i.reject({message:"File not found in the epub: "+t,stack:new Error().stack}),i.promise}handleResponse(t,e){let i;return e=="json"?i=JSON.parse(t):Ne(e)?i=Ut(t,"text/xml"):e=="xhtml"?i=Ut(t,"application/xhtml+xml"):e=="html"||e=="htm"?i=Ut(t,"text/html"):i=t,i}getBlob(t,e){const i=window.decodeURIComponent(t.substr(1)),n=this.zip.file(i);if(n)return e=e||ge.lookup(n.name),n.async("uint8array").then(function(s){return new Blob([s],{type:e})})}getText(t,e){const i=window.decodeURIComponent(t.substr(1)),n=this.zip.file(i);if(n)return n.async("string").then(function(s){return s})}getBase64(t,e){const i=window.decodeURIComponent(t.substr(1)),n=this.zip.file(i);if(n)return e=e||ge.lookup(n.name),n.async("base64").then(function(s){return"data:"+e+";base64,"+s})}createUrl(t,e){const i=new st,n=window.URL||window.webkitURL||window.mozURL;let s,r;const o=e&&e.base64;return t in this.urlCache?(i.resolve(this.urlCache[t]),i.promise):(o?(r=this.getBase64(t),r&&r.then((function(l){this.urlCache[t]=l,i.resolve(l)}).bind(this))):(r=this.getBlob(t),r&&r.then((function(l){s=n.createObjectURL(l),this.urlCache[t]=s,i.resolve(s)}).bind(this))),r||i.reject({message:"File not found in the epub: "+t,stack:new Error().stack}),i.promise)}revokeUrl(t){const e=window.URL||window.webkitURL||window.mozURL,i=this.urlCache[t];i&&e.revokeObjectURL(i)}destroy(){const t=window.URL||window.webkitURL||window.mozURL;for(const e in this.urlCache)t.revokeObjectURL(e);this.zip=void 0,this.urlCache={}}}function ke(h){throw new Error('Could not dynamically require "'+h+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var si={exports:{}};/*!
5
+ localForage -- Offline Storage, Improved
6
+ Version 1.10.0
7
+ https://localforage.github.io/localForage
8
+ (c) 2013-2017 Mozilla, Apache License 2.0
9
+ */var Li;function _s(){return Li||(Li=1,(function(h,t){(function(e){h.exports=e()})(function(){return(function e(i,n,s){function r(f,m){if(!n[f]){if(!i[f]){var b=typeof ke=="function"&&ke;if(!m&&b)return b(f,!0);if(o)return o(f,!0);var E=new Error("Cannot find module '"+f+"'");throw E.code="MODULE_NOT_FOUND",E}var N=n[f]={exports:{}};i[f][0].call(N.exports,function(W){var T=i[f][1][W];return r(T||W)},N,N.exports,e,i,n,s)}return n[f].exports}for(var o=typeof ke=="function"&&ke,l=0;l<s.length;l++)r(s[l]);return r})({1:[function(e,i,n){(function(s){var r=s.MutationObserver||s.WebKitMutationObserver,o;if(r){var l=0,f=new r(W),m=s.document.createTextNode("");f.observe(m,{characterData:!0}),o=function(){m.data=l=++l%2}}else if(!s.setImmediate&&typeof s.MessageChannel<"u"){var b=new s.MessageChannel;b.port1.onmessage=W,o=function(){b.port2.postMessage(0)}}else"document"in s&&"onreadystatechange"in s.document.createElement("script")?o=function(){var D=s.document.createElement("script");D.onreadystatechange=function(){W(),D.onreadystatechange=null,D.parentNode.removeChild(D),D=null},s.document.documentElement.appendChild(D)}:o=function(){setTimeout(W,0)};var E,N=[];function W(){E=!0;for(var D,q,U=N.length;U;){for(q=N,N=[],D=-1;++D<U;)q[D]();U=N.length}E=!1}i.exports=T;function T(D){N.push(D)===1&&!E&&o()}}).call(this,typeof Oe<"u"?Oe:typeof self<"u"?self:typeof window<"u"?window:{})},{}],2:[function(e,i,n){var s=e(1);function r(){}var o={},l=["REJECTED"],f=["FULFILLED"],m=["PENDING"];i.exports=b;function b(R){if(typeof R!="function")throw new TypeError("resolver must be a function");this.state=m,this.queue=[],this.outcome=void 0,R!==r&&T(this,R)}b.prototype.catch=function(R){return this.then(null,R)},b.prototype.then=function(R,z){if(typeof R!="function"&&this.state===f||typeof z!="function"&&this.state===l)return this;var P=new this.constructor(r);if(this.state!==m){var Y=this.state===f?R:z;N(P,Y,this.outcome)}else this.queue.push(new E(P,R,z));return P};function E(R,z,P){this.promise=R,typeof z=="function"&&(this.onFulfilled=z,this.callFulfilled=this.otherCallFulfilled),typeof P=="function"&&(this.onRejected=P,this.callRejected=this.otherCallRejected)}E.prototype.callFulfilled=function(R){o.resolve(this.promise,R)},E.prototype.otherCallFulfilled=function(R){N(this.promise,this.onFulfilled,R)},E.prototype.callRejected=function(R){o.reject(this.promise,R)},E.prototype.otherCallRejected=function(R){N(this.promise,this.onRejected,R)};function N(R,z,P){s(function(){var Y;try{Y=z(P)}catch(_){return o.reject(R,_)}Y===R?o.reject(R,new TypeError("Cannot resolve promise with itself")):o.resolve(R,Y)})}o.resolve=function(R,z){var P=D(W,z);if(P.status==="error")return o.reject(R,P.value);var Y=P.value;if(Y)T(R,Y);else{R.state=f,R.outcome=z;for(var _=-1,I=R.queue.length;++_<I;)R.queue[_].callFulfilled(z)}return R},o.reject=function(R,z){R.state=l,R.outcome=z;for(var P=-1,Y=R.queue.length;++P<Y;)R.queue[P].callRejected(z);return R};function W(R){var z=R&&R.then;if(R&&(typeof R=="object"||typeof R=="function")&&typeof z=="function")return function(){z.apply(R,arguments)}}function T(R,z){var P=!1;function Y(F){P||(P=!0,o.reject(R,F))}function _(F){P||(P=!0,o.resolve(R,F))}function I(){z(_,Y)}var B=D(I);B.status==="error"&&Y(B.value)}function D(R,z){var P={};try{P.value=R(z),P.status="success"}catch(Y){P.status="error",P.value=Y}return P}b.resolve=q;function q(R){return R instanceof this?R:o.resolve(new this(r),R)}b.reject=U;function U(R){var z=new this(r);return o.reject(z,R)}b.all=$;function $(R){var z=this;if(Object.prototype.toString.call(R)!=="[object Array]")return this.reject(new TypeError("must be an array"));var P=R.length,Y=!1;if(!P)return this.resolve([]);for(var _=new Array(P),I=0,B=-1,F=new this(r);++B<P;)V(R[B],B);return F;function V(Z,G){z.resolve(Z).then(rt,function(H){Y||(Y=!0,o.reject(F,H))});function rt(H){_[G]=H,++I===P&&!Y&&(Y=!0,o.resolve(F,_))}}}b.race=X;function X(R){var z=this;if(Object.prototype.toString.call(R)!=="[object Array]")return this.reject(new TypeError("must be an array"));var P=R.length,Y=!1;if(!P)return this.resolve([]);for(var _=-1,I=new this(r);++_<P;)B(R[_]);return I;function B(F){z.resolve(F).then(function(V){Y||(Y=!0,o.resolve(I,V))},function(V){Y||(Y=!0,o.reject(I,V))})}}},{1:1}],3:[function(e,i,n){(function(s){typeof s.Promise!="function"&&(s.Promise=e(2))}).call(this,typeof Oe<"u"?Oe:typeof self<"u"?self:typeof window<"u"?window:{})},{2:2}],4:[function(e,i,n){var s=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(a){return typeof a}:function(a){return a&&typeof Symbol=="function"&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};function r(a,p){if(!(a instanceof p))throw new TypeError("Cannot call a class as a function")}function o(){try{if(typeof indexedDB<"u")return indexedDB;if(typeof webkitIndexedDB<"u")return webkitIndexedDB;if(typeof mozIndexedDB<"u")return mozIndexedDB;if(typeof OIndexedDB<"u")return OIndexedDB;if(typeof msIndexedDB<"u")return msIndexedDB}catch{return}}var l=o();function f(){try{if(!l||!l.open)return!1;var a=typeof openDatabase<"u"&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),p=typeof fetch=="function"&&fetch.toString().indexOf("[native code")!==-1;return(!a||p)&&typeof indexedDB<"u"&&typeof IDBKeyRange<"u"}catch{return!1}}function m(a,p){a=a||[],p=p||{};try{return new Blob(a,p)}catch(v){if(v.name!=="TypeError")throw v;for(var d=typeof BlobBuilder<"u"?BlobBuilder:typeof MSBlobBuilder<"u"?MSBlobBuilder:typeof MozBlobBuilder<"u"?MozBlobBuilder:WebKitBlobBuilder,y=new d,w=0;w<a.length;w+=1)y.append(a[w]);return y.getBlob(p.type)}}typeof Promise>"u"&&e(3);var b=Promise;function E(a,p){p&&a.then(function(d){p(null,d)},function(d){p(d)})}function N(a,p,d){typeof p=="function"&&a.then(p),typeof d=="function"&&a.catch(d)}function W(a){return typeof a!="string"&&(console.warn(a+" used as a key, but it is not a string."),a=String(a)),a}function T(){if(arguments.length&&typeof arguments[arguments.length-1]=="function")return arguments[arguments.length-1]}var D="local-forage-detect-blob-support",q=void 0,U={},$=Object.prototype.toString,X="readonly",R="readwrite";function z(a){for(var p=a.length,d=new ArrayBuffer(p),y=new Uint8Array(d),w=0;w<p;w++)y[w]=a.charCodeAt(w);return d}function P(a){return new b(function(p){var d=a.transaction(D,R),y=m([""]);d.objectStore(D).put(y,"key"),d.onabort=function(w){w.preventDefault(),w.stopPropagation(),p(!1)},d.oncomplete=function(){var w=navigator.userAgent.match(/Chrome\/(\d+)/),v=navigator.userAgent.match(/Edge\//);p(v||!w||parseInt(w[1],10)>=43)}}).catch(function(){return!1})}function Y(a){return typeof q=="boolean"?b.resolve(q):P(a).then(function(p){return q=p,q})}function _(a){var p=U[a.name],d={};d.promise=new b(function(y,w){d.resolve=y,d.reject=w}),p.deferredOperations.push(d),p.dbReady?p.dbReady=p.dbReady.then(function(){return d.promise}):p.dbReady=d.promise}function I(a){var p=U[a.name],d=p.deferredOperations.pop();if(d)return d.resolve(),d.promise}function B(a,p){var d=U[a.name],y=d.deferredOperations.pop();if(y)return y.reject(p),y.promise}function F(a,p){return new b(function(d,y){if(U[a.name]=U[a.name]||pt(),a.db)if(p)_(a),a.db.close();else return d(a.db);var w=[a.name];p&&w.push(a.version);var v=l.open.apply(l,w);p&&(v.onupgradeneeded=function(S){var C=v.result;try{C.createObjectStore(a.storeName),S.oldVersion<=1&&C.createObjectStore(D)}catch(A){if(A.name==="ConstraintError")console.warn('The database "'+a.name+'" has been upgraded from version '+S.oldVersion+" to version "+S.newVersion+', but the storage "'+a.storeName+'" already exists.');else throw A}}),v.onerror=function(S){S.preventDefault(),y(v.error)},v.onsuccess=function(){var S=v.result;S.onversionchange=function(C){C.target.close()},d(S),I(a)}})}function V(a){return F(a,!1)}function Z(a){return F(a,!0)}function G(a,p){if(!a.db)return!0;var d=!a.db.objectStoreNames.contains(a.storeName),y=a.version<a.db.version,w=a.version>a.db.version;if(y&&(a.version!==p&&console.warn('The database "'+a.name+`" can't be downgraded from version `+a.db.version+" to version "+a.version+"."),a.version=a.db.version),w||d){if(d){var v=a.db.version+1;v>a.version&&(a.version=v)}return!0}return!1}function rt(a){return new b(function(p,d){var y=new FileReader;y.onerror=d,y.onloadend=function(w){var v=btoa(w.target.result||"");p({__local_forage_encoded_blob:!0,data:v,type:a.type})},y.readAsBinaryString(a)})}function H(a){var p=z(atob(a.data));return m([p],{type:a.type})}function K(a){return a&&a.__local_forage_encoded_blob}function Q(a){var p=this,d=p._initReady().then(function(){var y=U[p._dbInfo.name];if(y&&y.dbReady)return y.dbReady});return N(d,a,a),d}function tt(a){_(a);for(var p=U[a.name],d=p.forages,y=0;y<d.length;y++){var w=d[y];w._dbInfo.db&&(w._dbInfo.db.close(),w._dbInfo.db=null)}return a.db=null,V(a).then(function(v){return a.db=v,G(a)?Z(a):v}).then(function(v){a.db=p.db=v;for(var S=0;S<d.length;S++)d[S]._dbInfo.db=v}).catch(function(v){throw B(a,v),v})}function it(a,p,d,y){y===void 0&&(y=1);try{var w=a.db.transaction(a.storeName,p);d(null,w)}catch(v){if(y>0&&(!a.db||v.name==="InvalidStateError"||v.name==="NotFoundError"))return b.resolve().then(function(){if(!a.db||v.name==="NotFoundError"&&!a.db.objectStoreNames.contains(a.storeName)&&a.version<=a.db.version)return a.db&&(a.version=a.db.version+1),Z(a)}).then(function(){return tt(a).then(function(){it(a,p,d,y-1)})}).catch(d);d(v)}}function pt(){return{forages:[],db:null,dbReady:null,deferredOperations:[]}}function Ot(a){var p=this,d={db:null};if(a)for(var y in a)d[y]=a[y];var w=U[d.name];w||(w=pt(),U[d.name]=w),w.forages.push(p),p._initReady||(p._initReady=p.ready,p.ready=Q);var v=[];function S(){return b.resolve()}for(var C=0;C<w.forages.length;C++){var A=w.forages[C];A!==p&&v.push(A._initReady().catch(S))}var L=w.forages.slice(0);return b.all(v).then(function(){return d.db=w.db,V(d)}).then(function(O){return d.db=O,G(d,p._defaultConfig.version)?Z(d):O}).then(function(O){d.db=w.db=O,p._dbInfo=d;for(var j=0;j<L.length;j++){var J=L[j];J!==p&&(J._dbInfo.db=d.db,J._dbInfo.version=d.version)}})}function _t(a,p){var d=this;a=W(a);var y=new b(function(w,v){d.ready().then(function(){it(d._dbInfo,X,function(S,C){if(S)return v(S);try{var A=C.objectStore(d._dbInfo.storeName),L=A.get(a);L.onsuccess=function(){var O=L.result;O===void 0&&(O=null),K(O)&&(O=H(O)),w(O)},L.onerror=function(){v(L.error)}}catch(O){v(O)}})}).catch(v)});return E(y,p),y}function dt(a,p){var d=this,y=new b(function(w,v){d.ready().then(function(){it(d._dbInfo,X,function(S,C){if(S)return v(S);try{var A=C.objectStore(d._dbInfo.storeName),L=A.openCursor(),O=1;L.onsuccess=function(){var j=L.result;if(j){var J=j.value;K(J)&&(J=H(J));var ot=a(J,j.key,O++);ot!==void 0?w(ot):j.continue()}else w()},L.onerror=function(){v(L.error)}}catch(j){v(j)}})}).catch(v)});return E(y,p),y}function Qt(a,p,d){var y=this;a=W(a);var w=new b(function(v,S){var C;y.ready().then(function(){return C=y._dbInfo,$.call(p)==="[object Blob]"?Y(C.db).then(function(A){return A?p:rt(p)}):p}).then(function(A){it(y._dbInfo,R,function(L,O){if(L)return S(L);try{var j=O.objectStore(y._dbInfo.storeName);A===null&&(A=void 0);var J=j.put(A,a);O.oncomplete=function(){A===void 0&&(A=null),v(A)},O.onabort=O.onerror=function(){var ot=J.error?J.error:J.transaction.error;S(ot)}}catch(ot){S(ot)}})}).catch(S)});return E(w,d),w}function ie(a,p){var d=this;a=W(a);var y=new b(function(w,v){d.ready().then(function(){it(d._dbInfo,R,function(S,C){if(S)return v(S);try{var A=C.objectStore(d._dbInfo.storeName),L=A.delete(a);C.oncomplete=function(){w()},C.onerror=function(){v(L.error)},C.onabort=function(){var O=L.error?L.error:L.transaction.error;v(O)}}catch(O){v(O)}})}).catch(v)});return E(y,p),y}function Et(a){var p=this,d=new b(function(y,w){p.ready().then(function(){it(p._dbInfo,R,function(v,S){if(v)return w(v);try{var C=S.objectStore(p._dbInfo.storeName),A=C.clear();S.oncomplete=function(){y()},S.onabort=S.onerror=function(){var L=A.error?A.error:A.transaction.error;w(L)}}catch(L){w(L)}})}).catch(w)});return E(d,a),d}function Tt(a){var p=this,d=new b(function(y,w){p.ready().then(function(){it(p._dbInfo,X,function(v,S){if(v)return w(v);try{var C=S.objectStore(p._dbInfo.storeName),A=C.count();A.onsuccess=function(){y(A.result)},A.onerror=function(){w(A.error)}}catch(L){w(L)}})}).catch(w)});return E(d,a),d}function Ct(a,p){var d=this,y=new b(function(w,v){if(a<0){w(null);return}d.ready().then(function(){it(d._dbInfo,X,function(S,C){if(S)return v(S);try{var A=C.objectStore(d._dbInfo.storeName),L=!1,O=A.openKeyCursor();O.onsuccess=function(){var j=O.result;if(!j){w(null);return}a===0||L?w(j.key):(L=!0,j.advance(a))},O.onerror=function(){v(O.error)}}catch(j){v(j)}})}).catch(v)});return E(y,p),y}function qt(a){var p=this,d=new b(function(y,w){p.ready().then(function(){it(p._dbInfo,X,function(v,S){if(v)return w(v);try{var C=S.objectStore(p._dbInfo.storeName),A=C.openKeyCursor(),L=[];A.onsuccess=function(){var O=A.result;if(!O){y(L);return}L.push(O.key),O.continue()},A.onerror=function(){w(A.error)}}catch(O){w(O)}})}).catch(w)});return E(d,a),d}function Ft(a,p){p=T.apply(this,arguments);var d=this.config();a=typeof a!="function"&&a||{},a.name||(a.name=a.name||d.name,a.storeName=a.storeName||d.storeName);var y=this,w;if(!a.name)w=b.reject("Invalid arguments");else{var v=a.name===d.name&&y._dbInfo.db,S=v?b.resolve(y._dbInfo.db):V(a).then(function(C){var A=U[a.name],L=A.forages;A.db=C;for(var O=0;O<L.length;O++)L[O]._dbInfo.db=C;return C});a.storeName?w=S.then(function(C){if(C.objectStoreNames.contains(a.storeName)){var A=C.version+1;_(a);var L=U[a.name],O=L.forages;C.close();for(var j=0;j<O.length;j++){var J=O[j];J._dbInfo.db=null,J._dbInfo.version=A}var ot=new b(function(ht,mt){var ft=l.open(a.name,A);ft.onerror=function(It){var xe=ft.result;xe.close(),mt(It)},ft.onupgradeneeded=function(){var It=ft.result;It.deleteObjectStore(a.storeName)},ft.onsuccess=function(){var It=ft.result;It.close(),ht(It)}});return ot.then(function(ht){L.db=ht;for(var mt=0;mt<O.length;mt++){var ft=O[mt];ft._dbInfo.db=ht,I(ft._dbInfo)}}).catch(function(ht){throw(B(a,ht)||b.resolve()).catch(function(){}),ht})}}):w=S.then(function(C){_(a);var A=U[a.name],L=A.forages;C.close();for(var O=0;O<L.length;O++){var j=L[O];j._dbInfo.db=null}var J=new b(function(ot,ht){var mt=l.deleteDatabase(a.name);mt.onerror=function(){var ft=mt.result;ft&&ft.close(),ht(mt.error)},mt.onblocked=function(){console.warn('dropInstance blocked for database "'+a.name+'" until all open connections are closed')},mt.onsuccess=function(){var ft=mt.result;ft&&ft.close(),ot(ft)}});return J.then(function(ot){A.db=ot;for(var ht=0;ht<L.length;ht++){var mt=L[ht];I(mt._dbInfo)}}).catch(function(ot){throw(B(a,ot)||b.resolve()).catch(function(){}),ot})})}return E(w,p),w}var ne={_driver:"asyncStorage",_initStorage:Ot,_support:f(),iterate:dt,getItem:_t,setItem:Qt,removeItem:ie,clear:Et,length:Tt,key:Ct,keys:qt,dropInstance:Ft};function vt(){return typeof openDatabase=="function"}var St="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ct="~~local_forage_type~",Jt=/^~~local_forage_type~([^~]+)~/,jt="__lfsc__:",Dt=jt.length,kt="arbf",at="blob",yt="si08",se="ui08",ye="uic8",ae="si16",Vt="si32",we="ur16",he="ui32",be="fl32",c="fl64",u=Dt+kt.length,g=Object.prototype.toString;function x(a){var p=a.length*.75,d=a.length,y,w=0,v,S,C,A;a[a.length-1]==="="&&(p--,a[a.length-2]==="="&&p--);var L=new ArrayBuffer(p),O=new Uint8Array(L);for(y=0;y<d;y+=4)v=St.indexOf(a[y]),S=St.indexOf(a[y+1]),C=St.indexOf(a[y+2]),A=St.indexOf(a[y+3]),O[w++]=v<<2|S>>4,O[w++]=(S&15)<<4|C>>2,O[w++]=(C&3)<<6|A&63;return L}function k(a){var p=new Uint8Array(a),d="",y;for(y=0;y<p.length;y+=3)d+=St[p[y]>>2],d+=St[(p[y]&3)<<4|p[y+1]>>4],d+=St[(p[y+1]&15)<<2|p[y+2]>>6],d+=St[p[y+2]&63];return p.length%3===2?d=d.substring(0,d.length-1)+"=":p.length%3===1&&(d=d.substring(0,d.length-2)+"=="),d}function nt(a,p){var d="";if(a&&(d=g.call(a)),a&&(d==="[object ArrayBuffer]"||a.buffer&&g.call(a.buffer)==="[object ArrayBuffer]")){var y,w=jt;a instanceof ArrayBuffer?(y=a,w+=kt):(y=a.buffer,d==="[object Int8Array]"?w+=yt:d==="[object Uint8Array]"?w+=se:d==="[object Uint8ClampedArray]"?w+=ye:d==="[object Int16Array]"?w+=ae:d==="[object Uint16Array]"?w+=we:d==="[object Int32Array]"?w+=Vt:d==="[object Uint32Array]"?w+=he:d==="[object Float32Array]"?w+=be:d==="[object Float64Array]"?w+=c:p(new Error("Failed to get type for BinaryArray"))),p(w+k(y))}else if(d==="[object Blob]"){var v=new FileReader;v.onload=function(){var S=ct+a.type+"~"+k(this.result);p(jt+at+S)},v.readAsArrayBuffer(a)}else try{p(JSON.stringify(a))}catch(S){console.error("Couldn't convert value into a JSON string: ",a),p(null,S)}}function gt(a){if(a.substring(0,Dt)!==jt)return JSON.parse(a);var p=a.substring(u),d=a.substring(Dt,u),y;if(d===at&&Jt.test(p)){var w=p.match(Jt);y=w[1],p=p.substring(w[0].length)}var v=x(p);switch(d){case kt:return v;case at:return m([v],{type:y});case yt:return new Int8Array(v);case se:return new Uint8Array(v);case ye:return new Uint8ClampedArray(v);case ae:return new Int16Array(v);case we:return new Uint16Array(v);case Vt:return new Int32Array(v);case he:return new Uint32Array(v);case be:return new Float32Array(v);case c:return new Float64Array(v);default:throw new Error("Unkown type: "+d)}}var Nt={serialize:nt,deserialize:gt,stringToBuffer:x,bufferToString:k};function Ht(a,p,d,y){a.executeSql("CREATE TABLE IF NOT EXISTS "+p.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],d,y)}function zt(a){var p=this,d={db:null};if(a)for(var y in a)d[y]=typeof a[y]!="string"?a[y].toString():a[y];var w=new b(function(v,S){try{d.db=openDatabase(d.name,String(d.version),d.description,d.size)}catch(C){return S(C)}d.db.transaction(function(C){Ht(C,d,function(){p._dbInfo=d,v()},function(A,L){S(L)})},S)});return d.serializer=Nt,w}function wt(a,p,d,y,w,v){a.executeSql(d,y,w,function(S,C){C.code===C.SYNTAX_ERR?S.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[p.storeName],function(A,L){L.rows.length?v(A,C):Ht(A,p,function(){A.executeSql(d,y,w,v)},v)},v):v(S,C)},v)}function Xt(a,p){var d=this;a=W(a);var y=new b(function(w,v){d.ready().then(function(){var S=d._dbInfo;S.db.transaction(function(C){wt(C,S,"SELECT * FROM "+S.storeName+" WHERE key = ? LIMIT 1",[a],function(A,L){var O=L.rows.length?L.rows.item(0).value:null;O&&(O=S.serializer.deserialize(O)),w(O)},function(A,L){v(L)})})}).catch(v)});return E(y,p),y}function Yt(a,p){var d=this,y=new b(function(w,v){d.ready().then(function(){var S=d._dbInfo;S.db.transaction(function(C){wt(C,S,"SELECT * FROM "+S.storeName,[],function(A,L){for(var O=L.rows,j=O.length,J=0;J<j;J++){var ot=O.item(J),ht=ot.value;if(ht&&(ht=S.serializer.deserialize(ht)),ht=a(ht,ot.key,J+1),ht!==void 0){w(ht);return}}w()},function(A,L){v(L)})})}).catch(v)});return E(y,p),y}function Bt(a,p,d,y){var w=this;a=W(a);var v=new b(function(S,C){w.ready().then(function(){p===void 0&&(p=null);var A=p,L=w._dbInfo;L.serializer.serialize(p,function(O,j){j?C(j):L.db.transaction(function(J){wt(J,L,"INSERT OR REPLACE INTO "+L.storeName+" (key, value) VALUES (?, ?)",[a,O],function(){S(A)},function(ot,ht){C(ht)})},function(J){if(J.code===J.QUOTA_ERR){if(y>0){S(Bt.apply(w,[a,A,d,y-1]));return}C(J)}})})}).catch(C)});return E(v,d),v}function Rt(a,p,d){return Bt.apply(this,[a,p,d,1])}function $t(a,p){var d=this;a=W(a);var y=new b(function(w,v){d.ready().then(function(){var S=d._dbInfo;S.db.transaction(function(C){wt(C,S,"DELETE FROM "+S.storeName+" WHERE key = ?",[a],function(){w()},function(A,L){v(L)})})}).catch(v)});return E(y,p),y}function re(a){var p=this,d=new b(function(y,w){p.ready().then(function(){var v=p._dbInfo;v.db.transaction(function(S){wt(S,v,"DELETE FROM "+v.storeName,[],function(){y()},function(C,A){w(A)})})}).catch(w)});return E(d,a),d}function bt(a){var p=this,d=new b(function(y,w){p.ready().then(function(){var v=p._dbInfo;v.db.transaction(function(S){wt(S,v,"SELECT COUNT(key) as c FROM "+v.storeName,[],function(C,A){var L=A.rows.item(0).c;y(L)},function(C,A){w(A)})})}).catch(w)});return E(d,a),d}function Ie(a,p){var d=this,y=new b(function(w,v){d.ready().then(function(){var S=d._dbInfo;S.db.transaction(function(C){wt(C,S,"SELECT key FROM "+S.storeName+" WHERE id = ? LIMIT 1",[a+1],function(A,L){var O=L.rows.length?L.rows.item(0).key:null;w(O)},function(A,L){v(L)})})}).catch(v)});return E(y,p),y}function te(a){var p=this,d=new b(function(y,w){p.ready().then(function(){var v=p._dbInfo;v.db.transaction(function(S){wt(S,v,"SELECT key FROM "+v.storeName,[],function(C,A){for(var L=[],O=0;O<A.rows.length;O++)L.push(A.rows.item(O).key);y(L)},function(C,A){w(A)})})}).catch(w)});return E(d,a),d}function Ae(a){return new b(function(p,d){a.transaction(function(y){y.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],function(w,v){for(var S=[],C=0;C<v.rows.length;C++)S.push(v.rows.item(C).name);p({db:a,storeNames:S})},function(w,v){d(v)})},function(y){d(y)})})}function tn(a,p){p=T.apply(this,arguments);var d=this.config();a=typeof a!="function"&&a||{},a.name||(a.name=a.name||d.name,a.storeName=a.storeName||d.storeName);var y=this,w;return a.name?w=new b(function(v){var S;a.name===d.name?S=y._dbInfo.db:S=openDatabase(a.name,"","",0),a.storeName?v({db:S,storeNames:[a.storeName]}):v(Ae(S))}).then(function(v){return new b(function(S,C){v.db.transaction(function(A){function L(ot){return new b(function(ht,mt){A.executeSql("DROP TABLE IF EXISTS "+ot,[],function(){ht()},function(ft,It){mt(It)})})}for(var O=[],j=0,J=v.storeNames.length;j<J;j++)O.push(L(v.storeNames[j]));b.all(O).then(function(){S()}).catch(function(ot){C(ot)})},function(A){C(A)})})}):w=b.reject("Invalid arguments"),E(w,p),w}var en={_driver:"webSQLStorage",_initStorage:zt,_support:vt(),iterate:Yt,getItem:Xt,setItem:Rt,removeItem:$t,clear:re,length:bt,key:Ie,keys:te,dropInstance:tn};function nn(){try{return typeof localStorage<"u"&&"setItem"in localStorage&&!!localStorage.setItem}catch{return!1}}function vi(a,p){var d=a.name+"/";return a.storeName!==p.storeName&&(d+=a.storeName+"/"),d}function sn(){var a="_localforage_support_test";try{return localStorage.setItem(a,!0),localStorage.removeItem(a),!1}catch{return!0}}function rn(){return!sn()||localStorage.length>0}function on(a){var p=this,d={};if(a)for(var y in a)d[y]=a[y];return d.keyPrefix=vi(a,p._defaultConfig),rn()?(p._dbInfo=d,d.serializer=Nt,b.resolve()):b.reject()}function an(a){var p=this,d=p.ready().then(function(){for(var y=p._dbInfo.keyPrefix,w=localStorage.length-1;w>=0;w--){var v=localStorage.key(w);v.indexOf(y)===0&&localStorage.removeItem(v)}});return E(d,a),d}function hn(a,p){var d=this;a=W(a);var y=d.ready().then(function(){var w=d._dbInfo,v=localStorage.getItem(w.keyPrefix+a);return v&&(v=w.serializer.deserialize(v)),v});return E(y,p),y}function ln(a,p){var d=this,y=d.ready().then(function(){for(var w=d._dbInfo,v=w.keyPrefix,S=v.length,C=localStorage.length,A=1,L=0;L<C;L++){var O=localStorage.key(L);if(O.indexOf(v)===0){var j=localStorage.getItem(O);if(j&&(j=w.serializer.deserialize(j)),j=a(j,O.substring(S),A++),j!==void 0)return j}}});return E(y,p),y}function cn(a,p){var d=this,y=d.ready().then(function(){var w=d._dbInfo,v;try{v=localStorage.key(a)}catch{v=null}return v&&(v=v.substring(w.keyPrefix.length)),v});return E(y,p),y}function un(a){var p=this,d=p.ready().then(function(){for(var y=p._dbInfo,w=localStorage.length,v=[],S=0;S<w;S++){var C=localStorage.key(S);C.indexOf(y.keyPrefix)===0&&v.push(C.substring(y.keyPrefix.length))}return v});return E(d,a),d}function dn(a){var p=this,d=p.keys().then(function(y){return y.length});return E(d,a),d}function fn(a,p){var d=this;a=W(a);var y=d.ready().then(function(){var w=d._dbInfo;localStorage.removeItem(w.keyPrefix+a)});return E(y,p),y}function pn(a,p,d){var y=this;a=W(a);var w=y.ready().then(function(){p===void 0&&(p=null);var v=p;return new b(function(S,C){var A=y._dbInfo;A.serializer.serialize(p,function(L,O){if(O)C(O);else try{localStorage.setItem(A.keyPrefix+a,L),S(v)}catch(j){(j.name==="QuotaExceededError"||j.name==="NS_ERROR_DOM_QUOTA_REACHED")&&C(j),C(j)}})})});return E(w,d),w}function gn(a,p){if(p=T.apply(this,arguments),a=typeof a!="function"&&a||{},!a.name){var d=this.config();a.name=a.name||d.name,a.storeName=a.storeName||d.storeName}var y=this,w;return a.name?w=new b(function(v){a.storeName?v(vi(a,y._defaultConfig)):v(a.name+"/")}).then(function(v){for(var S=localStorage.length-1;S>=0;S--){var C=localStorage.key(S);C.indexOf(v)===0&&localStorage.removeItem(C)}}):w=b.reject("Invalid arguments"),E(w,p),w}var mn={_driver:"localStorageWrapper",_initStorage:on,_support:nn(),iterate:ln,getItem:hn,setItem:pn,removeItem:fn,clear:an,length:dn,key:cn,keys:un,dropInstance:gn},vn=function(p,d){return p===d||typeof p=="number"&&typeof d=="number"&&isNaN(p)&&isNaN(d)},yn=function(p,d){for(var y=p.length,w=0;w<y;){if(vn(p[w],d))return!0;w++}return!1},yi=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},Ee={},wi={},le={INDEXEDDB:ne,WEBSQL:en,LOCALSTORAGE:mn},wn=[le.INDEXEDDB._driver,le.WEBSQL._driver,le.LOCALSTORAGE._driver],Le=["dropInstance"],Ze=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(Le),bn={description:"",driver:wn.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function En(a,p){a[p]=function(){var d=arguments;return a.ready().then(function(){return a[p].apply(a,d)})}}function Qe(){for(var a=1;a<arguments.length;a++){var p=arguments[a];if(p)for(var d in p)p.hasOwnProperty(d)&&(yi(p[d])?arguments[0][d]=p[d].slice():arguments[0][d]=p[d])}return arguments[0]}var xn=(function(){function a(p){r(this,a);for(var d in le)if(le.hasOwnProperty(d)){var y=le[d],w=y._driver;this[d]=w,Ee[w]||this.defineDriver(y)}this._defaultConfig=Qe({},bn),this._config=Qe({},this._defaultConfig,p),this._driverSet=null,this._initDriver=null,this._ready=!1,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch(function(){})}return a.prototype.config=function(d){if((typeof d>"u"?"undefined":s(d))==="object"){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var y in d){if(y==="storeName"&&(d[y]=d[y].replace(/\W/g,"_")),y==="version"&&typeof d[y]!="number")return new Error("Database version must be a number.");this._config[y]=d[y]}return"driver"in d&&d.driver?this.setDriver(this._config.driver):!0}else return typeof d=="string"?this._config[d]:this._config},a.prototype.defineDriver=function(d,y,w){var v=new b(function(S,C){try{var A=d._driver,L=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!d._driver){C(L);return}for(var O=Ze.concat("_initStorage"),j=0,J=O.length;j<J;j++){var ot=O[j],ht=!yn(Le,ot);if((ht||d[ot])&&typeof d[ot]!="function"){C(L);return}}var mt=function(){for(var xe=function(Tn){return function(){var Nn=new Error("Method "+Tn+" is not implemented by the current driver"),bi=b.reject(Nn);return E(bi,arguments[arguments.length-1]),bi}},Je=0,Sn=Le.length;Je<Sn;Je++){var ti=Le[Je];d[ti]||(d[ti]=xe(ti))}};mt();var ft=function(xe){Ee[A]&&console.info("Redefining LocalForage driver: "+A),Ee[A]=d,wi[A]=xe,S()};"_support"in d?d._support&&typeof d._support=="function"?d._support().then(ft,C):ft(!!d._support):ft(!0)}catch(It){C(It)}});return N(v,y,w),v},a.prototype.driver=function(){return this._driver||null},a.prototype.getDriver=function(d,y,w){var v=Ee[d]?b.resolve(Ee[d]):b.reject(new Error("Driver not found."));return N(v,y,w),v},a.prototype.getSerializer=function(d){var y=b.resolve(Nt);return N(y,d),y},a.prototype.ready=function(d){var y=this,w=y._driverSet.then(function(){return y._ready===null&&(y._ready=y._initDriver()),y._ready});return N(w,d,d),w},a.prototype.setDriver=function(d,y,w){var v=this;yi(d)||(d=[d]);var S=this._getSupportedDrivers(d);function C(){v._config.driver=v.driver()}function A(j){return v._extend(j),C(),v._ready=v._initStorage(v._config),v._ready}function L(j){return function(){var J=0;function ot(){for(;J<j.length;){var ht=j[J];return J++,v._dbInfo=null,v._ready=null,v.getDriver(ht).then(A).catch(ot)}C();var mt=new Error("No available storage method found.");return v._driverSet=b.reject(mt),v._driverSet}return ot()}}var O=this._driverSet!==null?this._driverSet.catch(function(){return b.resolve()}):b.resolve();return this._driverSet=O.then(function(){var j=S[0];return v._dbInfo=null,v._ready=null,v.getDriver(j).then(function(J){v._driver=J._driver,C(),v._wrapLibraryMethodsWithReady(),v._initDriver=L(S)})}).catch(function(){C();var j=new Error("No available storage method found.");return v._driverSet=b.reject(j),v._driverSet}),N(this._driverSet,y,w),this._driverSet},a.prototype.supports=function(d){return!!wi[d]},a.prototype._extend=function(d){Qe(this,d)},a.prototype._getSupportedDrivers=function(d){for(var y=[],w=0,v=d.length;w<v;w++){var S=d[w];this.supports(S)&&y.push(S)}return y},a.prototype._wrapLibraryMethodsWithReady=function(){for(var d=0,y=Ze.length;d<y;d++)En(this,Ze[d])},a.prototype.createInstance=function(d){return new a(d)},a})(),_n=new xn;i.exports=_n},{3:3}]},{},[4])(4)})})(si)),si.exports}var Ss=_s();const Oi=Rn(Ss);class Ji{constructor(t,e,i){this.urlCache={},this.storage=void 0,this.name=t,this.requester=e||Ce,this.resolver=i,this.online=!0,this.checkRequirements(),this.addListeners()}checkRequirements(){try{let t;typeof Oi>"u"&&(t=Oi),this.storage=t.createInstance({name:this.name})}catch{throw new Error("localForage lib not loaded")}}addListeners(){this._status=this.status.bind(this),window.addEventListener("online",this._status),window.addEventListener("offline",this._status)}removeListeners(){window.removeEventListener("online",this._status),window.removeEventListener("offline",this._status),this._status=void 0}status(t){const e=navigator.onLine;this.online=e,e?this.emit("online",this):this.emit("offline",this)}add(t,e){const i=t.resources.map(n=>{const{href:s}=n,r=this.resolver(s),o=window.encodeURIComponent(r);return this.storage.getItem(o).then(l=>!l||e?this.requester(r,"binary").then(f=>this.storage.setItem(o,f)):l)});return Promise.all(i)}put(t,e,i){const n=window.encodeURIComponent(t);return this.storage.getItem(n).then(s=>s||this.requester(t,"binary",e,i).then(r=>this.storage.setItem(n,r)))}request(t,e,i,n){return this.online?this.requester(t,e,i,n).then(s=>(this.put(t),s)):this.retrieve(t,e)}retrieve(t,e){let i;const n=new Zt(t);return e||(e=n.extension),e=="blob"?i=this.getBlob(t):i=this.getText(t),i.then(s=>{const r=new st;let o;return s?(o=this.handleResponse(s,e),r.resolve(o)):r.reject({message:"File not found in storage: "+t,stack:new Error().stack}),r.promise})}handleResponse(t,e){let i;return e=="json"?i=JSON.parse(t):Ne(e)?i=Ut(t,"text/xml"):e=="xhtml"?i=Ut(t,"application/xhtml+xml"):e=="html"||e=="htm"?i=Ut(t,"text/html"):i=t,i}getBlob(t,e){const i=window.encodeURIComponent(t);return this.storage.getItem(i).then(function(n){if(n)return e=e||ge.lookup(t),new Blob([n],{type:e})})}getText(t,e){const i=window.encodeURIComponent(t);return e=e||ge.lookup(t),this.storage.getItem(i).then(function(n){const s=new st,r=new FileReader;if(!n)return;const o=new Blob([n],{type:e});return r.addEventListener("loadend",()=>{s.resolve(r.result)}),r.readAsText(o,e),s.promise})}getBase64(t,e){const i=window.encodeURIComponent(t);return e=e||ge.lookup(t),this.storage.getItem(i).then(n=>{const s=new st,r=new FileReader;if(!n)return;const o=new Blob([n],{type:e});return r.addEventListener("loadend",()=>{s.resolve(r.result)}),r.readAsDataURL(o),s.promise})}createUrl(t,e){const i=new st,n=window.URL||window.webkitURL||window.mozURL;let s,r;const o=e&&e.base64;return t in this.urlCache?(i.resolve(this.urlCache[t]),i.promise):(o?(r=this.getBase64(t),r&&r.then((function(l){this.urlCache[t]=l,i.resolve(l)}).bind(this))):(r=this.getBlob(t),r&&r.then((function(l){s=n.createObjectURL(l),this.urlCache[t]=s,i.resolve(s)}).bind(this))),r||i.reject({message:"File not found in storage: "+t,stack:new Error().stack}),i.promise)}revokeUrl(t){const e=window.URL||window.webkitURL||window.mozURL,i=this.urlCache[t];i&&e.revokeObjectURL(i)}destroy(){const t=window.URL||window.webkitURL||window.mozURL;for(const e in this.urlCache)t.revokeObjectURL(e);this.urlCache={},this.removeListeners()}}Wt(Ji.prototype);class ri{constructor(t){this.interactive="",this.fixedLayout="",this.openToSpread="",this.orientationLock="",t&&this.parse(t)}parse(t){if(!t)return this;const e=lt(t,"display_options");return e?(Kt(e,"option").forEach(n=>{let s="";switch(n.childNodes.length&&(s=n.childNodes[0].nodeValue??""),n.attributes.name.value){case"interactive":this.interactive=s;break;case"fixed-layout":this.fixedLayout=s;break;case"open-to-spread":this.openToSpread=s;break;case"orientation-lock":this.orientationLock=s;break}}),this):this}destroy(){this.interactive=void 0,this.fixedLayout=void 0,this.openToSpread=void 0,this.orientationLock=void 0}}const Di="META-INF/container.xml",Ts="META-INF/com.apple.ibooks.display-options.xml",Lt={BINARY:"binary",BASE64:"base64",EPUB:"epub",OPF:"opf",MANIFEST:"json",DIRECTORY:"directory"};class Ke{constructor(t,e){typeof e>"u"&&typeof t!="string"&&!(t instanceof Blob)&&!(t instanceof ArrayBuffer)&&(e=t,t=void 0),this.settings=xt(this.settings||{},{requestMethod:void 0,requestCredentials:void 0,requestHeaders:void 0,encoding:void 0,replacements:void 0,canonical:void 0,openAs:void 0,store:void 0}),xt(this.settings,e),this.opening=new st,this.opened=this.opening.promise,this.isOpen=!1,this.loading={manifest:new st,spine:new st,metadata:new st,cover:new st,navigation:new st,pageList:new st,resources:new st,displayOptions:new st},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise,resources:this.loading.resources.promise,displayOptions:this.loading.displayOptions.promise},this.ready=Promise.all([this.loaded.manifest,this.loaded.spine,this.loaded.metadata,this.loaded.cover,this.loaded.navigation,this.loaded.resources,this.loaded.displayOptions]),this.isRendered=!1,this.request=this.settings.requestMethod||Ce,this.spine=new Kn,this.locations=new $i(this.spine,this.load.bind(this)),this.navigation=void 0,this.pageList=void 0,this.url=void 0,this.path=void 0,this.archived=!1,this.archive=void 0,this.storage=void 0,this.resources=void 0,this.rendition=void 0,this.container=void 0,this.packaging=void 0,this.displayOptions=void 0,this.settings.store&&this.store(this.settings.store),t&&this.open(t,this.settings.openAs).catch(i=>{const n=new Error("Cannot load book at "+t);this.emit(M.BOOK.OPEN_FAILED,n)})}open(t,e){let i;const n=e||this.determineType(t);return n===Lt.BINARY?(this.archived=!0,this.url=new Pt("/",""),i=this.openEpub(t)):n===Lt.BASE64?(this.archived=!0,this.url=new Pt("/",""),i=this.openEpub(t,n)):n===Lt.EPUB?(this.archived=!0,this.url=new Pt("/",""),i=this.request(t,"binary",this.settings.requestCredentials,this.settings.requestHeaders).then(this.openEpub.bind(this))):n==Lt.OPF?(this.url=new Pt(t),i=this.openPackaging(this.url.Path.toString())):n==Lt.MANIFEST?(this.url=new Pt(t),i=this.openManifest(this.url.Path.toString())):(this.url=new Pt(t),i=this.openContainer(Di).then(this.openPackaging.bind(this))),i}openEpub(t,e){return this.unarchive(t,e||this.settings.encoding).then(()=>this.openContainer(Di)).then(i=>this.openPackaging(i))}openContainer(t){return this.load(t).then(e=>(this.container=new Zn(e),this.resolve(this.container.packagePath)))}openPackaging(t){return this.path=new Zt(t),this.load(t).then(e=>(this.packaging=new Ri(e),this.unpack(this.packaging)))}openManifest(t){return this.path=new Zt(t),this.load(t).then(e=>(this.packaging=new Ri,this.packaging.load(e),this.unpack(this.packaging)))}load(t,e){const i=this.resolve(t);return this.archived?this.archive.request(i):this.request(i,void 0,this.settings.requestCredentials,this.settings.requestHeaders)}resolve(t,e){if(!t)return"";let i=t;return t.indexOf("://")>-1?t:(this.path&&(i=this.path.resolve(t)),e!=!1&&this.url&&(i=this.url.resolve(i)),i)}canonical(t){let e=t;return t?(this.settings.canonical?e=this.settings.canonical(t):e=this.resolve(t,!0),e):""}determineType(t){let e;return this.settings.encoding==="base64"?Lt.BASE64:typeof t!="string"?Lt.BINARY:(e=new Pt(t).path().extension,e&&(e=e.replace(/\?.*$/,"")),e?e==="epub"?Lt.EPUB:e==="opf"?Lt.OPF:e==="json"?Lt.MANIFEST:Lt.BINARY:Lt.DIRECTORY)}unpack(t){this.package=t,this.packaging.metadata.layout===""?this.load(this.url.resolve(Ts)).then(e=>{this.displayOptions=new ri(e),this.loading.displayOptions.resolve(this.displayOptions)}).catch(e=>{this.displayOptions=new ri,this.loading.displayOptions.resolve(this.displayOptions)}):(this.displayOptions=new ri,this.loading.displayOptions.resolve(this.displayOptions)),this.spine.unpack(this.packaging,this.resolve.bind(this),this.canonical.bind(this)),this.resources=new es(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(()=>{this.loading.navigation.resolve(this.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&&this.settings.replacements!="none"?this.replacements().then(()=>{this.loaded.displayOptions.then(()=>{this.opening.resolve(this)})}).catch(e=>{console.error(e)}):this.loaded.displayOptions.then(()=>{this.opening.resolve(this)})}loadNavigation(t){const e=t.navPath||t.ncxPath,i=t.toc;return i?new Promise((n,s)=>{this.navigation=new ii(i),t.pageList&&(this.pageList=new ni(t.pageList)),n(this.navigation)}):e?this.load(e,"xml").then(n=>(this.navigation=new ii(n),this.pageList=new ni(n),this.navigation)):new Promise((n,s)=>{this.navigation=new ii,this.pageList=new ni,n(this.navigation)})}section(t){return this.spine.get(t)}renderTo(t,e){return this.rendition=new Ge(this,e),this.rendition.attachTo(t),this.rendition}setRequestCredentials(t){this.settings.requestCredentials=t}setRequestHeaders(t){this.settings.requestHeaders=t}unarchive(t,e){return this.archive=new xs,this.archive.open(t,e==="base64")}store(t){const e=this.settings.replacements&&this.settings.replacements!=="none",i=this.url,n=this.settings.requestMethod||Ce.bind(this);return this.storage=new Ji(t,n,this.resolve.bind(this)),this.request=this.storage.request.bind(this.storage),this.opened.then(()=>{this.archived&&(this.storage.requester=this.archive.request.bind(this.archive));const s=(r,o)=>{o.output=this.resources.substitute(r,o.url)};this.resources.settings.replacements=e||"blobUrl",this.resources.replacements().then(()=>this.resources.replaceCss()),this.storage.on("offline",()=>{this.url=new Pt("/",""),this.spine.hooks.serialize.register(s)}),this.storage.on("online",()=>{this.url=i,this.spine.hooks.serialize.deregister(s)})}),this.storage}coverUrl(){return this.loaded.cover.then(()=>this.cover?this.archived?this.archive.createUrl(this.cover):this.cover:null)}replacements(){return this.spine.hooks.serialize.register((t,e)=>{e.output=this.resources.substitute(t,e.url)}),this.resources.replacements().then(()=>this.resources.replaceCss()).then(()=>{})}getRange(t){const e=new et(t),i=this.spine.get(e.spinePos),n=this.load.bind(this);return i?i.load(n).then(function(s){return e.toRange(i.document)}):new Promise((s,r)=>{r("CFI could not be found")})}key(t){const e=t||this.packaging.metadata.identifier||this.url.filename;return`epubjs:${Ye}:${e}`}destroy(){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}}Wt(Ke.prototype);function oe(h,t){return new Ke(h,t)}oe.VERSION=Ye;typeof global<"u"&&(globalThis.EPUBJS_VERSION=Ye);oe.Book=Ke;oe.Rendition=Ge;oe.Contents=$e;oe.CFI=et;oe.utils=Un;exports.Book=Ke;exports.Contents=$e;exports.EpubCFI=et;exports.Layout=mi;exports.Rendition=Ge;exports.default=oe;
10
+ //# sourceMappingURL=epub.cjs.map