@nypl/web-reader 0.2.0-alpha.2 → 0.2.0-alpha.3

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.
package/dist/cjs/index.js CHANGED
@@ -603,7 +603,7 @@ and ensure you are accounting for this risk.
603
603
  <span>There was an error loading this page.</span>
604
604
  <button class="go-back">Go back</button>
605
605
  <button class="try-again">Try again</button>
606
- `,vh=It(Ng()),CF=It(nH()),h0=It(yu());me();var Lu=class{constructor(){this.onBackwardSwipe=()=>{},this.onForwardSwipe=()=>{},this.setupEvents=t=>{var e=null,r=null,n=this;t.addEventListener("touchstart",function(i){i.changedTouches.length===1&&(e=i)},!1),t.addEventListener("touchend",function(i){if(i.changedTouches.length!==1||!e)return;let a=e.changedTouches[0],o=i.changedTouches[0];if(!a)return;let s=window.devicePixelRatio,l=(a.clientX-o.clientX)/s,f=(a.clientY-o.clientY)/s;if(Math.abs(l)<Lu.TAP_TOLERANCE&&Math.abs(f)<Lu.TAP_TOLERANCE){if(r){e=null,r=null;return}if(i.timeStamp-e.timeStamp>Lu.LONG_PRESS_MS){e=null,r=null;return}e=null,r=i;return}if(r=null,i.timeStamp-e.timeStamp>Lu.SLOW_SWIPE_MS){e=null;return}let c=(a.clientY-o.clientY)/(a.clientX-o.clientX);if(Math.abs(c)>.5){e=null;return}l<0?n.onBackwardSwipe(i):n.onForwardSwipe(i),e=null},!1)}}},yh=Lu;yh.TAP_TOLERANCE=10;yh.LONG_PRESS_MS=500;yh.SLOW_SWIPE_MS=500;me();var _F=class{constructor(){this.onBackwardSwipe=()=>{},this.onForwardSwipe=()=>{},this.setupEvents=t=>{this.focusin(t),this.keydown(t)},this.focusin=t=>{let e=this;t.addEventListener("focusin",function(r){e.delegate.view.snap(r.target)},!0)},this.keydown=t=>{let e=this;t.addEventListener("keydown",function(r){let n=r.target;if(/input|select|option|textarea/i.test(n.tagName)||!(n.ownerDocument||n).defaultView.getSelection().isCollapsed)return;switch(r.key){case"ArrowRight":e.onForwardSwipe(r);break;case"ArrowLeft":e.onBackwardSwipe(r);break}},!1)}}};me();var OF=It(yu()),SF=class{constructor(t){this.enforceSampleRead=(0,OF.debounce)(e=>{var p,A,h;let n=Math.round(e.locations.totalProgression*100)<=((p=this.delegate.sample)==null?void 0:p.limit);this.delegate.view.layout==="fixed"&&!n&&e.locations.position<=((A=this.delegate.sample)==null?void 0:A.minimum)&&(n=!0);let i={37:1,38:0,39:1,40:1,32:1,33:1,34:1,35:1,36:1};function a(b){b.preventDefault()}function o(b){i[b.keyCode]&&!n&&a(b)}let s=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){s=!0}}))}catch(b){}let l=s?{passive:!1}:!1;function f(b){b=b||window.event;let w=Math.max(-1,Math.min(1,b.wheelDelta||-b.detail));return w==1,w==-1&&!n&&b.preventDefault(),!1}let c;function g(b){b=b||window.event;let w=b.target||b.srcElement,_=b.touches[0].clientY;if(!(_>c)){if(_<c&&!n)return w.className.match(/\baltNav\b/)||(b.returnValue=!1,b.cancelable&&(b.cancelBubble=!0),b.preventDefault&&b.cancelable&&(b.preventDefault(),b.stopPropagation())),!1}return c=_,!1}function m(b){return b=b||window.event,c=b.touches[0].clientY,!1}window.addEventListener("mousewheel",f,l),window.addEventListener("DOMMouseScroll",f,l),window.addEventListener("keydown",o,l),window.addEventListener("touchmove",g,l),window.addEventListener("touchstart",m,l),n?(this.delegate.iframes[0].focus(),this.delegate.errorMessage&&(this.delegate.errorMessage.style.display="none",this.delegate.errorMessage.style.removeProperty("background-color"))):(this.delegate.iframes[0].blur(),this.delegate.errorMessage&&(this.delegate.errorMessage.style.display="block",this.delegate.errorMessage.style.backgroundColor="rgb(255, 255, 255)",this.delegate.errorMessage.innerHTML=(h=this.delegate.sample)==null?void 0:h.popup))},300),this.delegate=t}},Er=class{constructor(t,e=null,r=null,n=null,i,a,o,s,l,f,c,g,m){this.iframes=[],this.sideNavExpanded=!1,this.material=!1,this.currentChapterLink={},this.currentSpreadLinks={},this.upLink=null,this.didInitKeyboardEventHandler=!1,this.onResize=()=>{clearTimeout(this.timeout),this.timeout=setTimeout(this.handleResize.bind(this),200)},this.reload=()=>le(this,null,function*(){let p=null;if(this.annotator&&(p=yield this.annotator.getLastReadingPosition()),p){let A=this.publication.getAbsoluteHref(p.href);_e&&console.log(p.href),_e&&console.log(A),p.href=A,yield this.navigate(p)}}),this.savePosition=(0,h0.debounce)(()=>le(this,null,function*(){this.annotator&&(yield this.saveCurrentReadingPosition())}),200),this.checkResourcePosition=(0,h0.debounce)(()=>{var p,A,h,b,w,_;this.view.atStart()&&this.view.atEnd()?((p=this.api)==null?void 0:p.resourceFitsScreen)&&((A=this.api)==null||A.resourceFitsScreen()):this.view.atEnd()?((h=this.api)==null?void 0:h.resourceAtEnd)&&((b=this.api)==null||b.resourceAtEnd()):this.view.atStart()&&((w=this.api)==null?void 0:w.resourceAtStart)&&((_=this.api)==null||_.resourceAtStart())},200),this.settings=t,this.annotator=e,this.view=t.view,this.view.attributes=c,this.view.delegate=this,this.eventHandler=new mH,this.touchEventHandler=new yh,this.keyboardEventHandler=new _F,this.upLinkConfig=r,this.initialLastReadingPosition=n,this.publication=i,this.material=a,this.api=o,this.rights=s,this.tts=l,this.injectables=f,this.attributes=c||{margin:0},this.services=g,this.sample=m,this.sampleReadEventHandler=new SF(this)}static create(t){return le(this,null,function*(){let e=new this(t.settings,t.annotator||null,t.upLink||null,t.initialLastReadingPosition||null,t.publication,t.material,t.api,t.rights,t.tts,t.injectables,t.attributes||{margin:0},t.services,t.sample);return yield e.start(t.mainElement,t.headerMenu,t.footerMenu),new Promise(r=>r(e))})}stop(){var t;_e&&console.log("Iframe navigator stop"),Ge(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),Ge(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),Ge(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Ge(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),Ge(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Ge(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),Ge(this.tryAgainButton,"click",this.tryAgain.bind(this)),Ge(this.goBackButton,"click",Er.goBack.bind(this)),Ge(this.bookmarksControl,"keydown",this.hideBookmarksOnEscape.bind(this)),Ge(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),Ge(window,"resize",this.onResize),this.iframes.forEach(e=>{Ge(e,"resize",this.onResize)}),((t=this.rights)==null?void 0:t.enableMaterial)&&(this.mDropdowns&&this.mDropdowns.forEach(e=>{e.destroy()}),this.mCollapsibles&&this.mCollapsibles.forEach(e=>{e.destroy()}),this.mSidenav&&this.mSidenav.destroy(),this.mTabs&&this.mTabs.forEach(e=>{e.destroy()}))}start(t,e,r){return le(this,null,function*(){var p,A,h,b,w,_,E,y,u;this.headerMenu=e,this.mainElement=t;try{let d=rr(t,"main#iframe-wrapper");d.style.overflow="overlay";let v=Le(t,"main#iframe-wrapper iframe"),C=Le(t,"#second");if(v&&this.iframes.push(v),C&&this.iframes.push(C),window.matchMedia("screen and (max-width: 600px)").matches&&(this.settings.columnCount=1),this.iframes.length===0){d.style.overflow="overlay";let O=document.createElement("iframe");if(O.setAttribute("SCROLLING","no"),O.setAttribute("allowtransparency","true"),this.iframes.push(O),this.publication.isFixedLayout?(this.spreads=document.createElement("div"),this.firstSpread=document.createElement("div"),this.spreads.style.display="flex",this.spreads.style.alignItems="center",this.spreads.style.justifyContent="center",this.spreads.appendChild(this.firstSpread),this.firstSpread.appendChild(this.iframes[0]),d.appendChild(this.spreads)):(O.setAttribute("height","100%"),O.setAttribute("width","100%"),d.appendChild(this.iframes[0])),this.publication.isFixedLayout)if(this.settings.columnCount!==1){let x=document.createElement("div");this.spreads.appendChild(x);let R=document.createElement("iframe");R.setAttribute("SCROLLING","no"),R.setAttribute("allowtransparency","true"),R.style.opacity="1",R.style.border="none",R.style.overflow="hidden",this.iframes.push(R),x.appendChild(this.iframes[1]),this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 100% 120%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc",x.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, 0% 120%)",x.style.boxShadow="0 0 8px 2px #ccc"}else this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc";else this.iframes[0].style.paddingTop=((A=(p=this.attributes)==null?void 0:p.iframePaddingTop)!=null?A:0)+"px"}if(this.publication.isFixedLayout){let O=d.clientHeight;var n=this.iframes[0].parentElement.parentElement;n.style.height=O+40+"px"}else this.iframes.length===2&&this.iframes.pop();this.loadingMessage=Le(t,"#reader-loading"),this.loadingMessage&&(this.loadingMessage.innerHTML=wF,this.loadingMessage.style.display="none"),this.errorMessage=Le(t,"#reader-error"),this.errorMessage&&(this.errorMessage.innerHTML=EF,this.errorMessage.style.display="none"),this.tryAgainButton=Le(t,"button[class=try-again]"),this.goBackButton=Le(t,"button[class=go-back]"),this.infoTop=Le(t,"div[class='info top']"),this.infoBottom=Le(t,"div[class='info bottom']"),this.headerMenu&&(this.bookTitle=Le(this.headerMenu,"#book-title")),this.infoBottom&&(this.chapterTitle=Le(this.infoBottom,"span[class=chapter-title]")),this.infoBottom&&(this.chapterPosition=Le(this.infoBottom,"span[class=chapter-position]")),this.infoBottom&&(this.remainingPositions=Le(this.infoBottom,"span[class=remaining-positions]")),this.headerMenu&&(this.espandMenuIcon=Le(this.headerMenu,"#expand-menu")),this.headerMenu&&(this.links=Le(this.headerMenu,"ul.links.top")),this.headerMenu&&(this.linksTopLeft=Le(this.headerMenu,"#nav-mobile-left")),this.headerMenu&&(this.tocView=Le(this.headerMenu,"#container-view-toc")),this.headerMenu&&(this.landmarksView=Le(e,"#container-view-landmarks")),this.headerMenu&&(this.landmarksSection=Le(e,"#sidenav-section-landmarks")),this.headerMenu&&(this.pageListView=Le(e,"#container-view-pagelist")),this.headerMenu&&(this.goToPageView=Le(e,"#sidenav-section-gotopage")),this.headerMenu&&(this.goToPageNumberInput=Le(e,"#goToPageNumberInput")),this.headerMenu&&(this.goToPageNumberButton=Le(e,"#goToPageNumberButton")),r&&(this.linksBottom=Le(r,"ul.links.bottom")),r&&(this.linksMiddle=Le(r,"ul.links.middle")),this.headerMenu&&(this.nextChapterAnchorElement=Le(this.headerMenu,"a[rel=next]")),this.headerMenu&&(this.nextChapterBottomAnchorElement=Le(t,"#next-chapter")),r&&(this.nextPageAnchorElement=Le(r,"a[rel=next]")),this.headerMenu&&(this.previousChapterAnchorElement=Le(this.headerMenu,"a[rel=prev]")),this.headerMenu&&(this.previousChapterTopAnchorElement=Le(t,"#previous-chapter")),r&&(this.previousPageAnchorElement=Le(r,"a[rel=prev]")),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.newPosition=null,this.newElementId=null,this.isBeingStyled=!0,this.isLoading=!0,this.setupEvents(),this.settings.setIframe(this.iframes[0]),this.settings.onSettingsChange(this.handleResize.bind(this)),this.settings.onColumnSettingsChange(this.handleNumberOfIframes.bind(this)),this.settings.onViewChange(this.updateBookView.bind(this)),this.initialLastReadingPosition&&this.annotator.initLastReadingPosition(this.initialLastReadingPosition);var i=this;if(this.headerMenu)var a=Le(this.headerMenu,"#menu-button-search"),o=Le(this.headerMenu,"#menu-button-tts"),s=Le(this.headerMenu,"#menu-button-bookmark"),l=Le(this.headerMenu,"#menu-button-play"),f=Le(this.headerMenu,"#menu-button-pause"),c=Le(this.headerMenu,"#menu-button-mediaoverlay");if((h=this.rights)==null?void 0:h.enableMaterial){let O=document.querySelectorAll(".sidenav");O&&(i.mSidenav=vh.Sidenav.init(O,{edge:(w=(b=this.attributes)==null?void 0:b.sideNavPosition)!=null?w:"left"}));let x=document.querySelectorAll(".collapsible");x&&(i.mCollapsibles=vh.Collapsible.init(x,{accordion:!0}));let R=document.querySelectorAll(".dropdown-trigger");R&&(i.mDropdowns=vh.Dropdown.init(R,{alignment:"right",constrainWidth:!1,coverTrigger:!1,closeOnClick:!1,autoTrigger:!1,onOpenEnd:function(){i.mTabs.forEach(T=>{T.updateTabIndicator()})}}));let z=document.querySelectorAll(".tabs");if(z&&(i.mTabs=vh.Tabs.init(z)),this.headerMenu){if(!((_=this.rights)==null?void 0:_.enableBookmarks)){s&&s.parentElement.style.setProperty("display","none");var g=Le(this.headerMenu,"#sidenav-section-bookmarks");g&&g.style.setProperty("display","none")}if(!((E=this.rights)==null?void 0:E.enableAnnotations)){var m=Le(this.headerMenu,"#sidenav-section-highlights");m&&m.style.setProperty("display","none")}((y=this.rights)==null?void 0:y.enableTTS)||o&&o.parentElement.style.setProperty("display","none"),((u=this.rights)==null?void 0:u.enableSearch)||a&&a.parentElement.style.setProperty("display","none"),a&&this.view.delegate.publication.isFixedLayout&&a.parentElement.style.setProperty("display","none")}}else this.headerMenu&&(a&&a.parentElement.style.setProperty("display","none"),o&&o.parentElement.style.setProperty("display","none"),s&&s.parentElement.style.setProperty("display","none"));return this.hasMediaOverlays?(l&&l.parentElement.style.setProperty("display","block"),f&&f.parentElement.style.setProperty("display","block"),c&&c.parentElement.style.setProperty("display","block")):(l&&l.parentElement.style.setProperty("display","none"),f&&f.parentElement.style.setProperty("display","none"),c&&c.parentElement.style.setProperty("display","none")),yield this.loadManifest()}catch(d){return console.error(d),this.abortOnError(),Promise.reject(d)}})}setupEvents(){for(let t of this.iframes)Re(t,"load",this.handleIFrameLoad.bind(this));Re(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),Re(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),Re(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Re(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),Re(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Re(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),Re(this.tryAgainButton,"click",this.tryAgain.bind(this)),Re(this.goBackButton,"click",Er.goBack.bind(this)),Re(this.bookmarksControl,"keydown",this.hideBookmarksOnEscape.bind(this)),Re(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),Re(this.goToPageNumberInput,"keypress",this.goToPageNumber.bind(this)),Re(this.goToPageNumberButton,"click",this.goToPageNumber.bind(this)),Re(window,"resize",this.onResize);for(let t of this.iframes)Re(t,"resize",this.onResize)}setupModalFocusTrap(t,e,r){let n=9;e.addEventListener("keydown",i=>{if(Er.isDisplayed(t)){let a=i.keyCode===n,o=!!i.shiftKey;a&&o&&(r.focus(),i.preventDefault(),i.stopPropagation())}}),r.addEventListener("keydown",i=>{if(Er.isDisplayed(t)){let a=i.keyCode===n,o=!!i.shiftKey;a&&!o&&(e.focus(),i.preventDefault(),i.stopPropagation())}})}goToPageNumber(t){return le(this,null,function*(){if(this.goToPageNumberInput.value&&(t.key==="Enter"||t.type==="click")){var e=this.publication.pageList.filter(n=>n.href.slice(n.href.indexOf("#")+1).replace(/[^0-9]/g,"")===this.goToPageNumberInput.value);if(e&&e.length>0){var r=e[0];let n={progression:0};if(r.Href.indexOf("#")!==-1){let a=r.Href.slice(r.Href.indexOf("#")+1);a!==null&&(n={fragment:a})}let i={href:this.publication.getAbsoluteHref(r.Href),locations:n,type:r.TypeLink,title:r.Title};this.stopReadAloud(!0),this.navigate(i)}}})}updateBookView(){this.view.layout==="fixed"?(this.nextPageAnchorElement&&(this.nextPageAnchorElement.style.display="none"),this.previousPageAnchorElement&&(this.previousPageAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")):(this.settings.isPaginated().then(t=>{if(t)this.view.height=_u()-40-this.attributes.margin,this.infoBottom&&this.infoBottom.style.removeProperty("display"),document.body.onscroll=()=>{},this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextPageAnchorElement&&(this.nextPageAnchorElement.style.display="unset"),this.previousPageAnchorElement&&(this.previousPageAnchorElement.style.display="unset"),this.chapterTitle&&(this.chapterTitle.style.display="inline"),this.chapterPosition&&(this.chapterPosition.style.display="inline"),this.remainingPositions&&(this.remainingPositions.style.display="inline"),this.eventHandler&&(this.eventHandler.onInternalLink=this.handleInternalLink.bind(this),this.eventHandler.onClickThrough=this.handleClickThrough.bind(this)),this.touchEventHandler&&(this.touchEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.touchEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this)),this.keyboardEventHandler&&(this.keyboardEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.keyboardEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this));else{this.infoBottom&&(this.infoBottom.style.display="none"),this.nextPageAnchorElement&&(this.nextPageAnchorElement.style.display="none"),this.previousPageAnchorElement&&(this.previousPageAnchorElement.style.display="none"),this.view.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")):this.view.atStart()&&this.view.atEnd()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):this.view.atEnd()?(this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset")):this.view.atStart()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"));let e=(0,h0.debounce)(()=>{this.isScrolling=!1},200),r=rr(document,"#iframe-wrapper");r.onscroll=()=>le(this,null,function*(){this.isScrolling=!0,yield this.savePosition(),this.view.atEnd(),this.view.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")):(this.settings.isPaginated().then(n=>{n||(this.view.atStart()&&this.view.atEnd()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):this.view.atEnd()?(this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset")):this.view.atStart()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")))}),this.checkResourcePosition()),e()}),this.chapterTitle&&(this.chapterTitle.style.display="none"),this.chapterPosition&&(this.chapterPosition.style.display="none"),this.remainingPositions&&(this.remainingPositions.style.display="none"),this.eventHandler&&(this.eventHandler.onInternalLink=this.handleInternalLink.bind(this),this.eventHandler.onClickThrough=this.handleClickThrough.bind(this)),this.touchEventHandler&&(this.touchEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.touchEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this)),this.keyboardEventHandler&&(this.keyboardEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.keyboardEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this))}}),setTimeout(()=>le(this,null,function*(){var t;if(this.annotationModule!==void 0)yield this.annotationModule.drawHighlights();else if(((t=this.rights)==null?void 0:t.enableSearch)&&this.searchModule!==void 0&&this.highlighter!==void 0){for(let e of this.iframes)yield this.highlighter.destroyAllhighlights(e.contentDocument);this.searchModule.drawSearch()}}),200))}loadManifest(){return le(this,null,function*(){try{let e=(l,f,c,g=!1)=>{var m,p;c&&(m=c,l instanceof HTMLDivElement&&(p=l));var A=document.createElement("ul");g&&(A=document.createElement("ol")),A.className="sidenav-toc";let h=null;for(let b of f){let w=document.createElement("li"),_=document.createElement("a"),E=document.createElement("span");_.className="chapter-link",_.tabIndex=-1;let y="";b.Href?(y=this.publication.getAbsoluteHref(b.Href),_.href=y,_.innerHTML=b.Title||"",w.appendChild(_)):(E.innerHTML=b.Title||"",E.className="chapter-title",w.appendChild(E)),b.Children&&b.Children.length>0&&e(w,b.Children,null,!0),A.appendChild(w),h=_}h&&m&&this.setupModalFocusTrap(p,m,h),Re(A,"click",b=>{if(b.preventDefault(),b.stopPropagation(),b.target&&b.target.tagName.toLowerCase()==="a"){let w=b.target;if(w.className.indexOf("active")!==-1)this.hideView(p,m);else{m==null||m.focus();let _={progression:0};if(w.href.indexOf("#")!==-1){let y=w.href.slice(w.href.indexOf("#")+1);y!==null&&(_={fragment:y})}let E={href:w.href,locations:_,type:w.type,title:w.title};this.hideView(p,m),this.navigate(E)}}}),l.appendChild(A)},r=this.publication.tableOfContents,n=this.publication.landmarks,i=this.publication.pageList;if(this.tocView&&(r.length?e(this.tocView,r):this.tocView.parentElement.parentElement.removeChild(this.tocView.parentElement)),this.pageListView&&((i==null?void 0:i.length)?e(this.pageListView,i):this.pageListView.parentElement.parentElement.removeChild(this.pageListView.parentElement)),this.goToPageView&&((i==null?void 0:i.length)||this.goToPageView.parentElement.removeChild(this.goToPageView)),this.landmarksView&&((n==null?void 0:n.length)?e(this.landmarksView,n):this.landmarksSection.parentElement.removeChild(this.landmarksSection)),(this.links||this.linksTopLeft)&&this.upLinkConfig&&this.upLinkConfig.url){let l=this.upLinkConfig.url,f=this.upLinkConfig.label||"",c=this.upLinkConfig.ariaLabel||f;var t=bF(l.href,f,c);let g=document.createElement("li");g.classList.add("uplink-wrapper"),g.innerHTML=t,this.links?(this.links.insertBefore(g,this.links.firstChild),this.upLink=rr(this.links,"a[rel=up]")):(this.linksTopLeft.insertBefore(g,this.linksTopLeft.firstChild),this.upLink=rr(this.linksTopLeft,"a[rel=up]"))}let a=null;this.annotator&&(a=yield this.annotator.getLastReadingPosition());let o=this.publication.getStartLink(),s=null;if(o&&o.Href&&(s=this.publication.getAbsoluteHref(o.Href)),a){let l=this.publication.getAbsoluteHref(a.href);_e&&console.log(a.href),_e&&console.log(l),a.href=l,yield this.navigate(a)}else if(s){let l={href:s,locations:{progression:0},created:new Date,title:o.Title};yield this.navigate(l)}return new Promise(l=>l())}catch(e){return console.error(e),this.abortOnError(),new Promise((r,n)=>n(e)).catch(()=>{})}})}handleIFrameLoad(){return le(this,null,function*(){var n,i,a,o,s;this.errorMessage&&(this.errorMessage.style.display="none"),this.showLoadingMessageAfterDelay();try{let l=0;this.newPosition&&(l=this.newPosition.locations.progression),this.handleResize(),this.updateBookView(),yield this.settings.applyProperties();let f=this.currentChapterLink.href,c=this.publication.getPreviousSpineItem(f);c&&c.Href&&(this.previousChapterLink={href:c.Href,title:c.Title,type:c.TypeLink}),this.previousChapterAnchorElement&&(this.previousChapterLink?(this.previousChapterAnchorElement.href=this.publication.getAbsoluteHref(this.previousChapterLink.href),this.previousChapterAnchorElement.className=this.previousChapterAnchorElement.className.replace(" disabled","")):(this.previousChapterAnchorElement.removeAttribute("href"),this.previousChapterAnchorElement.className+=" disabled"));let g=this.publication.getNextSpineItem(f);g?this.nextChapterLink={href:g.Href,title:g.Title,type:g.TypeLink}:this.nextChapterLink=void 0,this.nextChapterAnchorElement&&(this.nextChapterLink?(this.nextChapterAnchorElement.href=this.publication.getAbsoluteHref(this.nextChapterLink.href),this.nextChapterAnchorElement.className=this.nextChapterAnchorElement.className.replace(" disabled","")):(this.nextChapterAnchorElement.removeAttribute("href"),this.nextChapterAnchorElement.className+=" disabled")),this.currentTocUrl!==null?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(f),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let m=this.publication.getSpineItem(f);m!==null&&(this.currentChapterLink.title=m.Title,this.currentChapterLink.type=m.TypeLink);let p=this.publication.getTOCItem(f);this.currentTocUrl!==null&&(p=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&p!==null&&p.Title&&(this.currentChapterLink.title=p.Title),!this.currentChapterLink.type&&p!==null&&p.TypeLink&&(this.currentChapterLink.title=p.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),yield this.injectInjectablesIntoIframeHead(),this.highlighter!==void 0&&(yield this.highlighter.initialize());let A=this.iframes[0].contentDocument.body;if(((n=this.rights)==null?void 0:n.enableTTS)&&((i=this.tts)==null?void 0:i.enableSplitter)&&(0,CF.default)({target:A,by:"lines"}),((a=this.rights)==null?void 0:a.enableContentProtection)&&this.contentProtectionModule!==void 0&&(yield this.contentProtectionModule.initialize()),this.eventHandler){for(let h of this.iframes)this.eventHandler.setupEvents(h.contentDocument),this.touchEventHandler.setupEvents(h.contentDocument),this.keyboardEventHandler.setupEvents(h.contentDocument);this.touchEventHandler.setupEvents(this.errorMessage),this.didInitKeyboardEventHandler||(this.keyboardEventHandler.delegate=this,this.keyboardEventHandler.keydown(document),this.didInitKeyboardEventHandler=!0)}if(this.view.layout!=="fixed"&&((o=this.view)==null?void 0:o.isScrollMode()))for(let h of this.iframes)this.view.setIframeHeight(h);if(this.annotationModule!==void 0&&(yield this.annotationModule.initialize()),(s=this.rights)==null?void 0:s.enableTTS)for(let h of this.iframes){let b=h.contentDocument.body;this.ttsModule!==void 0&&(yield this.ttsModule.initialize(b))}for(let h of this.iframes)for(var t=h.contentDocument.body.querySelectorAll('[*|type="pagebreak"]'),e=0;e<t.length;e++){var r=t[e];_e&&console.log(r),r.innerHTML.length===0&&(r.innerHTML=r.getAttribute("title")),r.className="epubPageBreak"}return this.timelineModule!==void 0&&(yield this.timelineModule.initialize()),this.mediaOverlayModule!==void 0&&(yield this.mediaOverlayModule.initialize()),setTimeout(()=>le(this,null,function*(){if(this.newElementId){let h=this.iframes[0].contentDocument.getElementById(this.newElementId);this.view.goToElement(h),this.newElementId=null}else this.newPosition&&this.newPosition.highlight?this.view.goToCssSelector(this.newPosition.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector):l>0&&this.view.goToPosition(l);this.newPosition=null,this.hideLoadingMessage(),this.showIframeContents(),yield this.updatePositionInfo()}),200),Promise.resolve()}catch(l){return console.error(l),this.abortOnError(),Promise.reject(l)}})}injectInjectablesIntoIframeHead(){return le(this,null,function*(){let t=[],e=r=>{let n=new Promise(i=>{r.onload=()=>{i(!0)}});t.push(n)};for(let r of this.iframes){let n=r.contentDocument.head;n&&(n.insertBefore(Er.createBase(this.currentChapterLink.href),n.firstChild),this.injectables.forEach(i=>{if(i.type==="style")if(i.fontFamily){if(this.settings.initAddedFont(),!i.systemFont){let a=Er.createCssLink(i.url);n.appendChild(a),e(a)}}else if(i.r2before){let a=Er.createCssLink(i.url);n.insertBefore(a,n.firstChild),e(a)}else if(i.r2default){let a=Er.createCssLink(i.url);n.insertBefore(a,n.childNodes[1]),e(a)}else if(i.r2after){i.appearance&&this.settings.initAddedAppearance();let a=Er.createCssLink(i.url);n.appendChild(a),e(a)}else{let a=Er.createCssLink(i.url);n.appendChild(a),e(a)}else if(i.type==="script"){let a=Er.createJavascriptLink(i.url,i.async);n.appendChild(a),e(a)}}))}t.length!==0&&(yield Promise.all(t))})}abortOnError(){this.errorMessage&&(this.errorMessage.style.display="block"),this.isLoading&&this.hideLoadingMessage()}tryAgain(){this.precessContentForIframe()}precessContentForIframe(){var s,l,f,c,g,m;let t=this;var e=this.publication.getSpineIndex(this.currentChapterLink.href),r=e%2==1;this.showLoadingMessageAfterDelay();function n(p,A){let b=new DOMParser().parseFromString(p,"application/xhtml+xml");b.head&&b.head.insertBefore(Er.createBase(A),b.head.firstChild);let w=b.documentElement.outerHTML,_=t.iframes[0].contentDocument;_.open(),_.write(w),_.close()}function i(p,A){let b=new DOMParser().parseFromString(p,"application/xhtml+xml");b.head&&b.head.insertBefore(Er.createBase(A),b.head.firstChild);let w=b.documentElement.outerHTML,_=t.iframes[1].contentDocument;_.open(),_.write(w),_.close()}let a=new URL(this.currentChapterLink.href),o=window.location.protocol===a.protocol&&window.location.port===a.port&&window.location.hostname===a.hostname;if((s=this.api)==null?void 0:s.getContent)if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(this.currentSpreadLinks.left={href:this.currentChapterLink.href},(l=this.api)==null||l.getContent(this.currentChapterLink.href).then(p=>{p===void 0?o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){n.call(this,A,this.currentChapterLink.href)})):n.call(this,p,this.currentChapterLink.href)}),this.iframes.length===2)if(e<this.publication.readingOrder.length-1){let p=this.publication.getNextSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.right={href:A},(f=this.api)==null||f.getContent(A).then(h=>{h===void 0?o?this.iframes[1].src=A:fetch(A).then(b=>b.text()).then(b=>le(this,null,function*(){i.call(this,b,A),this.currentSpreadLinks.right={href:A}})):i.call(this,h,A)})}else this.iframes[1].src="about:blank"}else{if(e>0){let p=this.publication.getPreviousSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.left={href:A},(c=this.api)==null||c.getContent(A).then(h=>{h===void 0?o?this.iframes[0].src=A:fetch(A).then(b=>b.text()).then(b=>le(this,null,function*(){n.call(this,b,A)})):n.call(this,h,A)})}else this.iframes[0].src="about:blank";this.iframes.length===2&&this.publication.isFixedLayout&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},this.api.getContent(this.currentChapterLink.href).then(p=>{p===void 0?o?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){i.call(this,A,this.currentChapterLink.href)})):i.call(this,p,this.currentChapterLink.href)}))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},(g=this.api)==null||g.getContent(this.currentChapterLink.href).then(p=>{p===void 0?o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){n.call(this,A,this.currentChapterLink.href)})):n.call(this,p,this.currentChapterLink.href)});else(m=this.api)==null||m.getContent(this.currentChapterLink.href).then(p=>{this.currentSpreadLinks.left={href:this.currentChapterLink.href},p===void 0?o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){n.call(this,A,this.currentChapterLink.href)})):n.call(this,p,this.currentChapterLink.href)});else if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(o){if(this.iframes[0].src=this.currentChapterLink.href,this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.iframes.length===2)if(e<this.publication.readingOrder.length-1){let p=this.publication.getNextSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.iframes[1].src=A,this.currentSpreadLinks.right={href:A}}else this.iframes[1].src="about:blank"}else if(fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){n.call(this,p,this.currentChapterLink.href)})),this.iframes.length===2)if(e<this.publication.readingOrder.length-1){let p=this.publication.getNextSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.right={href:A},fetch(A).then(h=>h.text()).then(h=>le(this,null,function*(){i.call(this,h,A)}))}else this.iframes[1].src="about:blank"}else{if(e>0){let p=this.publication.getPreviousSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.left={href:A},o?(this.iframes[0].src=A,this.iframes.length===2&&(this.iframes[1].src=this.currentChapterLink.href)):(fetch(A).then(h=>h.text()).then(h=>le(this,null,function*(){n.call(this,h,A)})),this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},fetch(this.currentChapterLink.href).then(h=>h.text()).then(h=>le(this,null,function*(){i.call(this,h,this.currentChapterLink.href)}))))}else this.iframes[0].src="about:blank";this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},o?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){i.call(this,p,this.currentChapterLink.href)})))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){n.call(this,p,this.currentChapterLink.href)}));else this.currentSpreadLinks.left={href:this.currentChapterLink.href},o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){n.call(this,p,this.currentChapterLink.href)}));this.publication.isFixedLayout&&setTimeout(()=>{let p=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).height,A=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).width;if(parseInt(p.replace("px",""))===0||parseInt(A.replace("px",""))===0){let u=dr(e===0&&this.iframes.length===2?this.iframes[1].contentDocument:this.iframes[0].contentDocument,"head");if(u){let d=Le(u,"meta[name=viewport]");if(d){var h=d.content,b=h.split(",").reduce((v,C)=>{var[O,x]=C.match(/[^\s;=]+/g);return v[O]=isNaN(Number(x))?x:+x,v},{});p=b.height+"px",A=b.width+"px"}}}var w=e===0&&this.iframes.length===2?this.iframes[1].parentElement.parentElement:this.iframes[0].parentElement.parentElement,_=(parseInt(getComputedStyle(w).width)-100)/(this.iframes.length===2?parseInt(A.replace("px",""))*2+200:parseInt(A.replace("px",""))),E=(parseInt(getComputedStyle(w).height)-100)/parseInt(p.replace("px","")),y=Math.min(_,E);w.style.transform="scale("+y+")";for(let u of this.iframes)u.style.height=p,u.style.width=A,u.parentElement.style.height=p},400)}static goBack(){window.history.back()}static isDisplayed(t){return t?t.className.indexOf(" active")!==-1:!1}static showElement(t,e){if(t){if(t.className=t.className.replace(" inactive",""),t.className.indexOf(" active")===-1&&(t.className+=" active"),t.setAttribute("aria-hidden","false"),e){e.setAttribute("aria-expanded","true");let i=e.querySelector(".icon.open");if(i&&(i.getAttribute("class")||"").indexOf(" inactive-icon")===-1){let o=(i.getAttribute("class")||"")+" inactive-icon";i.setAttribute("class",o)}let a=e.querySelector(".icon.close");if(a){let o=(a.getAttribute("class")||"").replace(" inactive-icon","");a.setAttribute("class",o)}}let r=Array.prototype.slice.call(t.querySelectorAll("button")),n=Array.prototype.slice.call(t.querySelectorAll("a"));for(let i of r)i.tabIndex=0;for(let i of n)i.tabIndex=0}}static hideElement(t,e){if(t){if(t.className=t.className.replace(" active",""),t.className.indexOf(" inactive")===-1&&(t.className+=" inactive"),t.setAttribute("aria-hidden","true"),e){e.setAttribute("aria-expanded","false");let i=e.querySelector(".icon.open");if(i){let o=(i.getAttribute("class")||"").replace(" inactive-icon","");i.setAttribute("class",o)}let a=e.querySelector(".icon.close");if(a&&(a.getAttribute("class")||"").indexOf(" inactive-icon")===-1){let o=(a.getAttribute("class")||"")+" inactive-icon";a.setAttribute("class",o)}}let r=Array.prototype.slice.call(t.querySelectorAll("button")),n=Array.prototype.slice.call(t.querySelectorAll("a"));for(let i of r)i.tabIndex=-1;for(let i of n)i.tabIndex=-1}}hideModal(t,e){for(let r of this.iframes)r.setAttribute("aria-hidden","false");this.upLink&&this.upLink.setAttribute("aria-hidden","false"),this.linksBottom&&this.linksBottom.setAttribute("aria-hidden","false"),this.linksMiddle&&this.linksMiddle.setAttribute("aria-hidden","false"),this.loadingMessage&&this.loadingMessage.setAttribute("aria-hidden","false"),this.errorMessage&&this.errorMessage.setAttribute("aria-hidden","false"),this.infoTop&&this.infoTop.setAttribute("aria-hidden","false"),this.infoBottom&&this.infoBottom.setAttribute("aria-hidden","false"),Er.hideElement(t,e)}handleEditClick(t){var e=t.target,r=Le(this.headerMenu,".sidenav");e.className.indexOf(" active")===-1?(e.className+=" active",r.className+=" expanded",e.innerText="unfold_less",this.sideNavExpanded=!0,this.bookmarkModule.showBookmarks(),this.annotationModule.showHighlights()):(e.className=e.className.replace(" active",""),r.className=r.className.replace(" expanded",""),e.innerText="unfold_more",this.sideNavExpanded=!1,this.bookmarkModule.showBookmarks(),this.annotationModule.showHighlights()),t.preventDefault(),t.stopPropagation()}get hasMediaOverlays(){return this.publication.hasMediaOverlays}startReadAloud(){var t,e;((t=this.rights)==null?void 0:t.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.startReadAloud():((e=this.rights)==null?void 0:e.enableTTS)&&this.highlighter.speakAll()}stopReadAloud(t=!1){var e,r,n;t?((e=this.rights)==null?void 0:e.enableTTS)&&this.highlighter.stopReadAloud():((r=this.rights)==null?void 0:r.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.stopReadAloud():((n=this.rights)==null?void 0:n.enableTTS)&&this.highlighter.stopReadAloud()}pauseReadAloud(){var t,e;((t=this.rights)==null?void 0:t.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.pauseReadAloud():((e=this.rights)==null?void 0:e.enableTTS)&&this.ttsModule.speakPause()}resumeReadAloud(){var t,e;((t=this.rights)==null?void 0:t.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.resumeReadAloud():((e=this.rights)==null?void 0:e.enableTTS)&&this.ttsModule.speakResume()}totalResources(){return this.publication.readingOrder.length}mostRecentNavigatedTocItem(){return this.publication.getRelativeHref(this.currentTOCRawLink)}currentResource(){let t=this.currentChapterLink.href;return this.publication.getSpineIndex(t)}currentLink(){if(this.settings.columnCount!==1&&this.currentSpreadLinks.left!==void 0&&this.currentSpreadLinks.right!==void 0){let e=this.publication.getSpineItem(this.currentSpreadLinks.left.href),r=this.publication.getSpineItem(this.currentSpreadLinks.right.href);return[e,r]}let t=this.currentChapterLink.href;return[this.publication.getSpineItem(t)]}tableOfContents(){return this.publication.tableOfContents}readingOrder(){return this.publication.readingOrder}atStart(){return this.view.atStart()}atEnd(){return this.view.atEnd()}previousPage(){this.handlePreviousPageClick(null)}nextPage(){this.handleNextPageClick(null)}previousResource(){this.handlePreviousChapterClick(null)}nextResource(){this.handleNextChapterClick(null)}goTo(t){var i;let e=(i=t.locations)!=null?i:{progression:0};if(t.href.indexOf("#")!==-1){let a=t.href.slice(t.href.indexOf("#")+1);a!==null&&(e=fn(st({},e),{fragment:a}))}let r=st({},t);r.locations=e;let n=this.publication.getAbsoluteHref(t.href);_e&&console.log(t.href),_e&&console.log(n),r.href=n,this.stopReadAloud(!0),this.navigate(r)}currentLocator(){var r,n;let t;if(((n=(r=this.rights)==null?void 0:r.autoGeneratePositions)!=null?n:!1)&&this.publication.positions||this.publication.positions){let i=this.publication.positionsByHref(this.publication.getRelativeHref(this.currentChapterLink.href)),a=Math.ceil(this.view.getCurrentPosition()*(i.length-1));t=i[a]}else{var e=this.publication.getTOCItem(this.currentChapterLink.href);this.currentTocUrl!==null&&(e=this.publication.getTOCItem(this.currentTocUrl)),e===null&&(e=this.publication.getTOCItemAbsolute(this.currentChapterLink.href)),t={href:e.Href,type:this.currentChapterLink.type,title:this.currentChapterLink.title,locations:{}}}return t.locations.progression=this.view.getCurrentPosition(),t.displayInfo={resourceScreenIndex:Math.round(this.view.getCurrentPage()),resourceScreenCount:Math.round(this.view.getPageCount())},t}positions(){return this.publication.positions?this.publication.positions:[]}goToPosition(t){if(this.publication.positions){let e=this.publication.positions.filter(r=>r.locations.position===parseInt(String(t)))[0];this.goTo(e)}}snapToElement(t){this.view.snap(t)}applyAttributes(t){this.attributes=t,this.view.attributes=t,this.handleResize()}handlePreviousPageClick(t){this.stopReadAloud(!0),this.view.layout==="fixed"?this.handlePreviousChapterClick(t):(this.view.atStart()?this.handlePreviousChapterClick(t):(this.view.goToPreviousPage(),this.updatePositionInfo(),this.savePosition()),t&&(t.preventDefault(),t.stopPropagation()))}handleNextPageClick(t){var r,n,i,a,o,s;let e=!0;if(((r=this.sample)==null?void 0:r.isSampleRead)&&this.publication.positions){let l=this.currentLocator();e=Math.round(l.locations.totalProgression*100)<=((n=this.sample)==null?void 0:n.limit),this.view.layout==="fixed"&&!e&&l.locations.position<=((i=this.sample)==null?void 0:i.minimum)&&(e=!0)}(e&&((a=this.sample)==null?void 0:a.isSampleRead)&&this.publication.positions||!((o=this.sample)==null?void 0:o.isSampleRead)||!this.publication.positions)&&(this.stopReadAloud(!0),this.view.layout==="fixed"?this.handleNextChapterClick(t):(this.view.atEnd()?this.handleNextChapterClick(t):(this.view.goToNextPage(),this.updatePositionInfo(),this.savePosition()),t&&(t.preventDefault(),t.stopPropagation()))),!e&&((s=this.sample)==null?void 0:s.isSampleRead)&&this.publication.positions&&t&&(t.preventDefault(),t.stopPropagation())}handleClickThrough(t){this.mDropdowns&&this.mDropdowns.forEach(e=>{e.close()})}handleInternalLink(t){let e=t.target,r={progression:0},n=e;if(n.href.indexOf("#")!==-1){let a=n.href.slice(n.href.indexOf("#")+1);a!==null&&(r={fragment:a})}let i={href:n.href,locations:r,type:n.type,title:n.title};t.preventDefault(),t.stopPropagation(),this.stopReadAloud(!0),this.navigate(i)}handleNumberOfIframes(){if(this.publication.isFixedLayout){if(this.settings.columnCount!==1){if(this.iframes.length===1){var t=document.createElement("iframe");t.setAttribute("SCROLLING","no"),t.setAttribute("allowtransparency","true"),t.style.opacity="1",t.style.border="none",t.style.overflow="hidden",this.iframes.push(t)}let e=document.createElement("div");this.spreads.appendChild(e),e.appendChild(this.iframes[1]),this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 100% 120%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc",e.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, 0% 120%)",e.style.boxShadow="0 0 8px 2px #ccc"}else this.iframes.length===2&&(this.iframes.pop(),this.spreads.removeChild(this.spreads.lastChild)),this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc";this.precessContentForIframe()}}handleResize(){if(this.isScrolling)return;let t=this.view.getCurrentPosition();if(this.publication.isFixedLayout){var e=this.publication.getSpineIndex(this.currentChapterLink.href);let l=_u()-40-this.attributes.margin;var r=e===0&&this.iframes.length===2?this.iframes[1].parentElement.parentElement:this.iframes[0].parentElement.parentElement;r.style.height=l+40+"px";let f=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).height,c=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).width,g=dr(e===0&&this.iframes.length===2?this.iframes[1].contentDocument:this.iframes[0].contentDocument,"head");if(g){let m=Le(g,"meta[name=viewport]");if(m){var n=m.content,i=n.split(",").reduce((p,A)=>{var[h,b]=A.match(/[^\s;=]+/g);return p[h]=isNaN(Number(b))?b:+b,p},{});(parseInt(i.height)!==0||parseInt(i.width)!==0)&&(f=i.height+"px",c=i.width+"px")}}var a=(parseInt(getComputedStyle(r).width)-100)/(this.iframes.length===2?parseInt(c.replace("px",""))*2+200:parseInt(c.replace("px",""))),o=(parseInt(getComputedStyle(r).height)-100)/parseInt(f.replace("px","")),s=Math.min(a,o);r.style.transform="scale("+s+")";for(let m of this.iframes)m.style.height=f,m.style.width=c,m.parentElement.style.height=f}this.settings.applyProperties(),this.infoTop&&(this.infoTop.style.height=0+"px"),this.infoTop&&(this.infoTop.style.minHeight=0+"px"),this.infoBottom&&(this.infoBottom.style.height=this.attributes.bottomInfoHeight?this.attributes.bottomInfoHeight+"px":40+"px"),this.view.layout!=="fixed"&&this.settings.isPaginated().then(l=>{l?(this.view.height=_u()-40-this.attributes.margin,this.infoBottom&&this.infoBottom.style.removeProperty("display")):this.infoBottom&&(this.infoBottom.style.display="none")}),setTimeout(()=>{var l;if(this.view.layout!=="fixed"&&((l=this.view)==null?void 0:l.isScrollMode()))for(let f of this.iframes)this.view.setIframeHeight(f)},100),setTimeout(()=>le(this,null,function*(){var l,f;this.view.goToPosition(t),yield this.updatePositionInfo(!1),this.annotationModule!==void 0?this.annotationModule.handleResize():((l=this.rights)==null?void 0:l.enableSearch)&&(yield this.searchModule.handleResize()),((f=this.rights)==null?void 0:f.enableContentProtection)&&this.contentProtectionModule!==void 0&&this.contentProtectionModule.handleResize()}),150)}updatePositionInfo(t=!0){return le(this,null,function*(){var e;if(this.view.layout==="fixed")this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");else if((e=this.view)==null?void 0:e.isPaginated()){let r=this.currentLocator(),n=r.displayInfo.resourceScreenIndex,i=r.displayInfo.resourceScreenCount,a=r.locations.remainingPositions;this.chapterPosition&&(a?this.chapterPosition.innerHTML="Page "+n+" of "+i:this.chapterPosition.innerHTML=""),this.remainingPositions&&(a?this.remainingPositions.innerHTML=a+" left in chapter":this.remainingPositions.innerHTML="Page "+n+" of "+i)}else this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");t&&(yield this.savePosition())})}handlePreviousChapterClick(t){if(this.view.layout==="fixed"&&this.settings.columnCount!==1){let e=this.publication.getSpineIndex(this.currentChapterLink.href);e=e-2,e<0&&(e=0);let r=this.publication.readingOrder[e],n={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(!0),this.navigate(n)}else if(this.previousChapterLink){let e={href:this.publication.getAbsoluteHref(this.previousChapterLink.href),locations:{progression:1},type:this.previousChapterLink.type,title:this.previousChapterLink.title};this.stopReadAloud(!0),this.navigate(e)}t&&(t.preventDefault(),t.stopPropagation())}handleNextChapterClick(t){if(this.view.layout==="fixed"&&this.settings.columnCount!==1){let e=this.publication.getSpineIndex(this.currentChapterLink.href);e=e+2,e>=this.publication.readingOrder.length-1&&(e=this.publication.readingOrder.length-1);let r=this.publication.readingOrder[e],n={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(!0),this.navigate(n)}else if(this.nextChapterLink){let e={href:this.publication.getAbsoluteHref(this.nextChapterLink.href),locations:{progression:0},type:this.nextChapterLink.type,title:this.nextChapterLink.title};this.stopReadAloud(!0),this.navigate(e)}t&&(t.preventDefault(),t.stopPropagation())}hideBookmarksOnEscape(t){let e=27;Er.isDisplayed(this.bookmarksView)&&t.keyCode===e&&this.hideModal(this.bookmarksView,this.bookmarksControl)}hideView(t,e){var r;this.view.layout!=="fixed"&&((r=this.view)==null?void 0:r.isScrollMode())&&(document.body.style.overflow="auto")}setActiveTOCItem(t){if(this.tocView){let e=Array.prototype.slice.call(this.tocView.querySelectorAll("li > a"));for(let n of e)n.className=n.className.replace(" active","");let r=this.tocView.querySelector('li > a[href^="'+t+'"]');r&&(r.className+=" active")}}navigate(t){return le(this,null,function*(){var n,i,a,o,s,l;if(this.publication.getTOCItem(t.href)){var r=!1;if(t.href.indexOf("#")!==-1){let f=t.href.slice(0,t.href.indexOf("#"));f===this.currentChapterLink.href&&(r=!0),this.currentChapterLink.href=f,this.currentChapterLink.type=t.type,this.currentChapterLink.title=t.title}else t.href===this.currentChapterLink.href&&(r=!0),this.currentChapterLink.href=t.href,this.currentChapterLink.type=t.type,this.currentChapterLink.title=t.title;if(this.currentSpreadLinks.left!==void 0&&this.currentSpreadLinks.right!==void 0&&(t.href===this.currentSpreadLinks.left.href||t.href===this.currentSpreadLinks.right.href))return;if(r){if(t.href.indexOf("#")!==-1){let A=t.href.slice(t.href.indexOf("#")+1);t.locations={fragment:A}}if(this.newPosition=t,this.currentTOCRawLink=t.href,t.locations.fragment===void 0?this.currentTocUrl=null:(this.newElementId=t.locations.fragment,this.currentTocUrl=this.currentChapterLink.href+"#"+this.newElementId),this.newElementId){for(let A of this.iframes){let h=A.contentDocument.getElementById(this.newElementId);this.view.goToElement(h)}this.newElementId=null}else t.highlight?this.view.goToCssSelector(t.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector):this.view.goToPosition(t.locations.progression);let f=this.currentChapterLink.href,c=this.publication.getPreviousSpineItem(f);c&&c.Href&&(this.previousChapterLink={href:c.Href,type:c.TypeLink,title:c.Title}),this.previousChapterAnchorElement&&(this.previousChapterLink?(this.previousChapterAnchorElement.href=this.publication.getAbsoluteHref(this.previousChapterLink.href),this.previousChapterAnchorElement.className=this.previousChapterAnchorElement.className.replace(" disabled","")):(this.previousChapterAnchorElement.removeAttribute("href"),this.previousChapterAnchorElement.className+=" disabled"));let g=this.publication.getNextSpineItem(f);g?this.nextChapterLink={href:g.Href,type:g.TypeLink,title:g.Title}:this.nextChapterLink=void 0,this.nextChapterAnchorElement&&(this.nextChapterLink?(this.nextChapterAnchorElement.href=this.publication.getAbsoluteHref(this.nextChapterLink.href),this.nextChapterAnchorElement.className=this.nextChapterAnchorElement.className.replace(" disabled","")):(this.nextChapterAnchorElement.removeAttribute("href"),this.nextChapterAnchorElement.className+=" disabled")),this.currentTocUrl!==null?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(f),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let m=this.publication.getSpineItem(f);m!==null&&(this.currentChapterLink.title=m.Title,this.currentChapterLink.type=m.TypeLink);let p=this.publication.getTOCItem(f);this.currentTocUrl!==null&&(p=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&p!==null&&p.Title&&(this.currentChapterLink.title=p.Title),!this.currentChapterLink.type&&p!==null&&p.TypeLink&&(this.currentChapterLink.title=p.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),yield this.updatePositionInfo()}else{if(this.searchModule!==void 0&&this.searchModule.clearSearch(),t.locations.fragment===void 0?this.currentTocUrl=null:(this.newElementId=t.locations.fragment,this.currentTocUrl=this.currentChapterLink.href+"#"+this.newElementId),this.hideIframeContents(),this.showLoadingMessageAfterDelay(),t.locations===void 0&&(t.locations={progression:0}),this.newPosition=t,this.currentTOCRawLink=t.href,this.precessContentForIframe(),((n=this.rights)==null?void 0:n.enableContentProtection)&&this.contentProtectionModule!==void 0&&(yield this.contentProtectionModule.initializeResource()),((i=this.rights)==null?void 0:i.enableMediaOverlays)&&this.mediaOverlayModule!==void 0&&(yield this.mediaOverlayModule.initializeResource(this.currentLink())),((a=this.rights)==null?void 0:a.enableContentProtection)&&this.contentProtectionModule!==void 0&&this.contentProtectionModule.recalculate(300),this.annotationModule!==void 0)yield this.annotationModule.drawHighlights(),yield this.annotationModule.showHighlights();else if(((o=this.rights)==null?void 0:o.enableSearch)&&this.searchModule!==void 0&&this.highlighter!==void 0){for(let f of this.iframes)yield this.highlighter.destroyAllhighlights(f.contentDocument);this.searchModule.drawSearch()}this.view.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),((s=this.api)==null?void 0:s.resourceFitsScreen)&&((l=this.api)==null||l.resourceFitsScreen())):this.settings.isPaginated().then(f=>{f||(this.view.atStart()&&this.view.atEnd()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):this.view.atEnd()?(this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset")):this.view.atStart()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")))})}}else{let f=this.publication.getStartLink(),c=null;if(f&&f.Href&&(c=this.publication.getAbsoluteHref(f.Href)),c){let g={href:c,locations:{progression:0},created:new Date,title:f.Title};yield this.navigate(g)}}})}showIframeContents(){this.isBeingStyled=!1,setTimeout(()=>{this.isBeingStyled||this.iframes.forEach(t=>{t.style.opacity="1",t.style.border="none",t.style.overflow="hidden"})},150)}showLoadingMessageAfterDelay(){this.isLoading=!0,this.isLoading&&this.loadingMessage&&(this.loadingMessage.style.display="block",this.loadingMessage.classList.add("is-loading"))}hideIframeContents(){this.isBeingStyled=!0,this.iframes.forEach(t=>{t.style.opacity="0",t.style.border="none",t.style.overflow="hidden"})}hideLoadingMessage(){setTimeout(()=>{var t,e,r,n,i,a,o,s;this.isLoading=!1,this.loadingMessage&&(this.loadingMessage.style.display="none",this.loadingMessage.classList.remove("is-loading")),this.view.layout!=="fixed"&&(this.view.atStart()&&this.view.atEnd()?((t=this.api)==null?void 0:t.resourceFitsScreen)&&((e=this.api)==null||e.resourceFitsScreen()):this.view.atEnd()?((r=this.api)==null?void 0:r.resourceAtEnd)&&((n=this.api)==null||n.resourceAtEnd()):this.view.atStart()&&((i=this.api)==null?void 0:i.resourceAtStart)&&((a=this.api)==null||a.resourceAtStart())),((o=this.api)==null?void 0:o.resourceReady)&&((s=this.api)==null||s.resourceReady())},150)}saveCurrentReadingPosition(){return le(this,null,function*(){var e,r,n,i,a,o;if(this.annotator){var t=this.publication.getTOCItem(this.currentChapterLink.href);this.currentTocUrl!==null&&(t=this.publication.getTOCItem(this.currentTocUrl)),t===null&&(t=this.publication.getTOCItemAbsolute(this.currentChapterLink.href));let s={progression:this.view.getCurrentPosition()};if(t.Href.indexOf("#")!==-1){let f=t.Href.slice(t.Href.indexOf("#")+1);f!==null&&(s={progression:this.view.getCurrentPosition(),fragment:f})}let l;if(((r=(e=this.rights)==null?void 0:e.autoGeneratePositions)!=null?r:!1)&&this.publication.positions||this.publication.positions){let f=this.publication.positionsByHref(this.publication.getRelativeHref(t.Href)),c=Math.ceil(s.progression*(f.length-1)),g=f[c];g.locations.fragment=s.fragment,l=fn(st({},g),{href:t.Href,created:new Date,title:this.currentChapterLink.title})}else l={href:t.Href,locations:s,created:new Date,type:this.currentChapterLink.type,title:this.currentChapterLink.title};if(((n=this.sample)==null?void 0:n.isSampleRead)&&this.publication.positions&&((i=this.sampleReadEventHandler)==null||i.enforceSampleRead(l)),(a=this.api)==null?void 0:a.updateCurrentLocation)(o=this.api)==null||o.updateCurrentLocation(l).then(f=>le(this,null,function*(){return _e&&console.log("api updated current location",l),this.annotator.saveLastReadingPosition(l)}));else return _e&&console.log("save last reading position",l),this.annotator.saveLastReadingPosition(l)}else return new Promise(s=>s())})}static createBase(t){let e=document.createElement("base");return e.target="_self",e.href=t,e}static createCssLink(t){let e=document.createElement("link");return e.rel="stylesheet",e.type="text/css",e.href=t,e}static createJavascriptLink(t,e){let r=document.createElement("script");return r.type="text/javascript",r.src=t,r.async=e,r}};me();var yt=class{constructor(t){this.store=t.store}getLastReadingPosition(){return le(this,null,function*(){let t=yield this.store.get(yt.LAST_READING_POSITION);if(t){let e=JSON.parse(t);return new Promise(r=>r(e))}return new Promise(e=>e())})}initLastReadingPosition(t){return le(this,null,function*(){if(typeof t=="string")yield this.store.set(yt.LAST_READING_POSITION,t);else{let e=JSON.stringify(t);yield this.store.set(yt.LAST_READING_POSITION,e)}return new Promise(e=>e())})}saveLastReadingPosition(t){return le(this,null,function*(){if(typeof t=="string")yield this.store.set(yt.LAST_READING_POSITION,t);else{let e=JSON.stringify(t);yield this.store.set(yt.LAST_READING_POSITION,e)}return new Promise(e=>e())})}initBookmarks(t){return le(this,null,function*(){if(typeof t=="string"){let e=JSON.parse(t);return yield this.store.set(yt.BOOKMARKS,JSON.stringify(e)),new Promise(r=>r(t))}else return yield this.store.set(yt.BOOKMARKS,JSON.stringify(t)),new Promise(e=>e(t))})}saveBookmark(t){return le(this,null,function*(){let e=yield this.store.get(yt.BOOKMARKS);if(e){let r=JSON.parse(e);r.push(t),yield this.store.set(yt.BOOKMARKS,JSON.stringify(r))}else{let r=[];r.push(t),yield this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return new Promise(r=>r(t))})}locatorExists(t,e){return le(this,null,function*(){let r;switch(e){case ei.Bookmark:r=yt.BOOKMARKS;break}let n=yield this.store.get(r);return n&&JSON.parse(n).filter(o=>o.href===t.href&&o.locations.progression===t.locations.progression).length>0?new Promise(o=>o(t)):new Promise(i=>i())})}deleteBookmark(t){return le(this,null,function*(){let e=yield this.store.get(yt.BOOKMARKS);if(e){let r=JSON.parse(e);r=r.filter(n=>n.id!==t.id),yield this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return new Promise(r=>r(t))})}getBookmarks(t){return le(this,null,function*(){let e=yield this.store.get(yt.BOOKMARKS);if(e){let r=JSON.parse(e);if(t){let n=r.filter(i=>i.href===t);return n=n.sort((i,a)=>i.locations.progression-a.locations.progression),new Promise(i=>i(n))}return r=r.sort((n,i)=>n.locations.progression-i.locations.progression),new Promise(n=>n(r))}return new Promise(r=>r())})}initAnnotations(t){return le(this,null,function*(){let e;typeof t=="string"?e=JSON.parse(t):e=t;let r=[];return e.forEach(n=>{let i=`${n.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector}${n.highlight.selectionInfo.rangeInfo.startContainerChildTextNodeIndex}${n.highlight.selectionInfo.rangeInfo.startOffset}${n.highlight.selectionInfo.rangeInfo.endContainerElementCssSelector}${n.highlight.selectionInfo.rangeInfo.endContainerChildTextNodeIndex}${n.highlight.selectionInfo.rangeInfo.endOffset}`,a=Su.hash(i);n.highlight.id="R2_HIGHLIGHT_"+a;var o;o=n.color,Dr.isHexColor(o)&&(o=Dr.hexToRgbString(o)),n.highlight.color=o,n.highlight.pointerInteraction=!0,n.highlight.selectionInfo.cleanText=n.highlight.selectionInfo.rawText.trim().replace(/\n/g," ").replace(/\s\s+/g," "),r.push(n)}),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r)),new Promise(n=>n(r))})}saveAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let r=JSON.parse(e);r.push(t),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}else{let r=[];r.push(t),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return new Promise(r=>r(t))})}deleteAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let r=JSON.parse(e);r=r.filter(n=>n.id!==t),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return new Promise(r=>r(t))})}deleteSelectedAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let r=JSON.parse(e);r=r.filter(n=>n.highlight.id!==t.highlight.id),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return new Promise(r=>r(t))})}getAnnotations(){return le(this,null,function*(){let t=yield this.store.get(yt.ANNOTATIONS);if(t){let e=JSON.parse(t);return e=e.sort((r,n)=>r.locations.progression-n.locations.progression),new Promise(r=>r(e))}return new Promise(e=>e())})}getAnnotationPosition(t,e){return le(this,null,function*(){let r=yield this.store.get(yt.ANNOTATIONS);if(r){let a=JSON.parse(r).filter(o=>o.id===t);if(a.length>0){let o=e.document.getElementById(`${a[0].highlight.id}`);if(o){var n=parseInt((o.hasChildNodes?o.childNodes[0]:o).style.top.replace("px",""));return new Promise(s=>s(n))}}}return new Promise(i=>i())})}getAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let n=JSON.parse(e).filter(i=>i.highlight.id===t.id);if(n.length>0)return new Promise(i=>i(n[0]))}return new Promise(r=>r())})}},bh=yt;bh.LAST_READING_POSITION="last-reading-position";bh.BOOKMARKS="bookmarks";bh.ANNOTATIONS="annotations";me();me();var xF=class{constructor(){this.store={}}get(t){let e=this.store[t]||null;return new Promise(r=>r(e))}set(t,e){return this.store[t]=e,new Promise(r=>r())}remove(t){return this.store[t]=null,new Promise(e=>e())}},Q3=class{constructor(t){this.prefix=t.prefix,this.useLocalStorage=t.useLocalStorage;try{let e=t.prefix+"-"+String(Math.random());this.useLocalStorage?(window.localStorage.setItem(e,"test"),window.localStorage.removeItem(e)):(window.sessionStorage.setItem(e,"test"),window.sessionStorage.removeItem(e)),this.fallbackStore=null}catch(e){this.fallbackStore=new xF}}getLocalStorageKey(t){return this.prefix+"-"+t}get(t){return le(this,null,function*(){let e=null;return this.fallbackStore?e=yield this.fallbackStore.get(t):this.useLocalStorage?e=window.localStorage.getItem(this.getLocalStorageKey(t)):e=window.sessionStorage.getItem(this.getLocalStorageKey(t)),new Promise(r=>r(e))})}set(t,e){return le(this,null,function*(){return this.fallbackStore?yield this.fallbackStore.set(t,e):this.useLocalStorage?window.localStorage.setItem(this.getLocalStorageKey(t),e):window.sessionStorage.setItem(this.getLocalStorageKey(t),e),new Promise(r=>r())})}remove(t){return le(this,null,function*(){return this.fallbackStore?yield this.fallbackStore.remove(t):this.useLocalStorage?window.localStorage.removeItem(this.getLocalStorageKey(t)):window.sessionStorage.removeItem(this.getLocalStorageKey(t)),new Promise(e=>e())})}};me();var PF=It($f()),TF=It(Gr()),K3=class extends PF.Link{};K3=Rx([(0,TF.JsonObject)()],K3);function wh(t){let e,r,n,i;if(t instanceof Array)return t.map(function(a){return typeof a=="object"&&(a=wh(a)),a});e={};for(r in t)t.hasOwnProperty(r)&&(n=(r.charAt(0).toLowerCase()+r.slice(1)||r).toString(),i=t[r],(i instanceof Array||i!==null&&i.constructor===Object)&&(i=wh(i)),n==="href1"?e.href=i:n==="typeLink"?e.type=i:e[n]=i);return e}var p0=class{constructor(t,e,r,n,i,a,o,s,l,f,c,g){this.settings=t,this.ttsSettings=e,this.navigator=r,this.highlighter=n,this.bookmarkModule=i,this.annotationModule=a,this.ttsModule=o,this.searchModule=s,this.contentProtectionModule=l,this.timelineModule=f,this.mediaOverlaySettings=c,this.mediaOverlayModule=g,this.startReadAloud=()=>this.navigator.startReadAloud(),this.stopReadAloud=()=>this.navigator.stopReadAloud(),this.pauseReadAloud=()=>this.navigator.pauseReadAloud(),this.resumeReadAloud=()=>this.navigator.resumeReadAloud(),this.saveBookmark=()=>le(this,null,function*(){var m;if((m=this.navigator.rights)==null?void 0:m.enableBookmarks)return yield this.bookmarkModule.saveBookmark()}),this.deleteBookmark=m=>le(this,null,function*(){var p;if((p=this.navigator.rights)==null?void 0:p.enableBookmarks)return yield this.bookmarkModule.deleteBookmark(m)}),this.deleteAnnotation=m=>le(this,null,function*(){var p;return yield(p=this.annotationModule)==null?void 0:p.deleteAnnotation(m)}),this.addAnnotation=m=>le(this,null,function*(){var p;return yield(p=this.annotationModule)==null?void 0:p.addAnnotation(m)}),this.tableOfContents=()=>le(this,null,function*(){return yield wh(this.navigator.tableOfContents())}),this.readingOrder=()=>le(this,null,function*(){return yield wh(this.navigator.readingOrder())}),this.bookmarks=()=>le(this,null,function*(){var m;return((m=this.navigator.rights)==null?void 0:m.enableBookmarks)?yield this.bookmarkModule.getBookmarks():[]}),this.annotations=()=>le(this,null,function*(){var m,p;return(p=yield(m=this.annotationModule)==null?void 0:m.getAnnotations())!=null?p:[]}),this.search=(m,p)=>le(this,null,function*(){var A,h;return((A=this.navigator.rights)==null?void 0:A.enableSearch)?yield(h=this.searchModule)==null?void 0:h.search(m,p):[]}),this.goToSearchIndex=(m,p,A)=>le(this,null,function*(){var h,b;((h=this.navigator.rights)==null?void 0:h.enableSearch)&&(yield(b=this.searchModule)==null?void 0:b.goToSearchIndex(m,p,A))}),this.goToSearchID=(m,p,A)=>le(this,null,function*(){var h,b;((h=this.navigator.rights)==null?void 0:h.enableSearch)&&(yield(b=this.searchModule)==null?void 0:b.goToSearchID(m,p,A))}),this.clearSearch=()=>le(this,null,function*(){var m,p;((m=this.navigator.rights)==null?void 0:m.enableSearch)&&(yield(p=this.searchModule)==null?void 0:p.clearSearch())}),this.currentResource=()=>this.navigator.currentResource(),this.mostRecentNavigatedTocItem=()=>this.navigator.mostRecentNavigatedTocItem(),this.totalResources=()=>this.navigator.totalResources(),this.resetUserSettings=()=>le(this,null,function*(){return yield this.settings.resetUserSettings()}),this.applyUserSettings=m=>le(this,null,function*(){return yield this.settings.applyUserSettings(m)}),this.currentSettings=()=>this.settings.currentSettings,this.scroll=m=>le(this,null,function*(){return yield this.settings.scroll(m)}),this.increase=m=>le(this,null,function*(){var p,A;this.isTTSIncrementable(m)?((p=this.navigator.rights)==null?void 0:p.enableTTS)&&(yield this.ttsSettings.increase(m)):this.isMOIncrementable(m)?((A=this.navigator.rights)==null?void 0:A.enableMediaOverlays)&&(yield this.mediaOverlaySettings.increase(m)):yield this.settings.increase(m)}),this.decrease=m=>le(this,null,function*(){var p,A;this.isTTSIncrementable(m)?((p=this.navigator.rights)==null?void 0:p.enableTTS)&&(yield this.ttsSettings.decrease(m)):this.isMOIncrementable(m)?((A=this.navigator.rights)==null?void 0:A.enableMediaOverlays)&&(yield this.mediaOverlaySettings.decrease(m)):yield this.settings.decrease(m)}),this.resetTTSSettings=()=>{var m;((m=this.navigator.rights)==null?void 0:m.enableTTS)&&this.ttsSettings.resetTTSSettings()},this.applyTTSSettings=m=>{var p;((p=this.navigator.rights)==null?void 0:p.enableTTS)&&this.ttsSettings.applyTTSSettings(m)},this.applyTTSSetting=(m,p)=>{var A;((A=this.navigator.rights)==null?void 0:A.enableTTS)&&this.ttsSettings.applyTTSSetting(m,p)},this.applyPreferredVoice=m=>{var p;((p=this.navigator.rights)==null?void 0:p.enableTTS)&&this.ttsSettings.applyPreferredVoice(m)},this.resetMediaOverlaySettings=()=>le(this,null,function*(){var m;((m=this.navigator.rights)==null?void 0:m.enableMediaOverlays)&&(yield this.mediaOverlaySettings.resetMediaOverlaySettings())}),this.applyMediaOverlaySettings=m=>le(this,null,function*(){var p;((p=this.navigator.rights)==null?void 0:p.enableMediaOverlays)&&(yield this.mediaOverlaySettings.applyMediaOverlaySettings(m))}),this.goTo=m=>le(this,null,function*(){this.navigator.goTo(m)}),this.goToPosition=m=>le(this,null,function*(){return this.navigator.goToPosition(m)}),this.nextResource=()=>le(this,null,function*(){this.navigator.nextResource()}),this.previousResource=()=>le(this,null,function*(){this.navigator.previousResource()}),this.nextPage=()=>le(this,null,function*(){this.navigator.nextPage()}),this.previousPage=()=>le(this,null,function*(){this.navigator.previousPage()}),this.atStart=()=>le(this,null,function*(){return this.navigator.atStart()}),this.atEnd=()=>le(this,null,function*(){return this.navigator.atEnd()}),this.snapToElement=m=>le(this,null,function*(){this.navigator.snapToElement(m)}),this.applyAttributes=m=>{this.navigator.applyAttributes(m)},this.stop=()=>{var m,p,A,h,b,w,_,E,y;document.body.onscroll=()=>{},this.navigator.stop(),this.settings.stop(),(m=this.ttsSettings)==null||m.stop(),(p=this.ttsModule)==null||p.stop(),(A=this.bookmarkModule)==null||A.stop(),(h=this.annotationModule)==null||h.stop(),(b=this.searchModule)==null||b.stop(),(w=this.contentProtectionModule)==null||w.stop(),(_=this.timelineModule)==null||_.stop(),(E=this.mediaOverlaySettings)==null||E.stop(),(y=this.mediaOverlayModule)==null||y.stop()}}static build(t){return le(this,null,function*(){var x,R,z,T,P,I,H,j,S,B,L,F,D,q,V,k,K,de,oe,se,ae,ce,U,ee;((x=t.rights)==null?void 0:x.enableContentProtection)&&t.protection&&(yield J3.setupPreloadProtection(t.protection));let e=rr(document,"#D2Reader-Container"),r=Le(document,"#headerMenu"),n=Le(document,"#footerMenu"),i=t.url,a=new Q3({prefix:i.href,useLocalStorage:(R=t.useLocalStorage)!=null?R:!1}),o=new Q3({prefix:"r2d2bc-reader",useLocalStorage:(z=t.useLocalStorage)!=null?z:!1}),s=new bh({store:a}),l=(T=t.upLinkUrl)!=null?T:void 0,f=yield ih.fromUrl(i),c=RF(t,f);f.sample=c.sample,((I=(P=c.rights)==null?void 0:P.autoGeneratePositions)!=null?I:!0)?yield f.autoGeneratePositions():(((H=c.services)==null?void 0:H.positions)&&(yield f.fetchPositionsFromService((j=c.services)==null?void 0:j.positions.href)),((S=c.services)==null?void 0:S.weight)&&(yield f.fetchWeightsFromService((B=c.services)==null?void 0:B.weight.href)));let g=yield Ou.create({store:o,initialUserSettings:c.userSettings,headerMenu:r,material:c.material,api:c.api,injectables:((F=(L=f.Metadata.Rendition)==null?void 0:L.Layout)!=null?F:"unknown")==="fixed"?c.injectablesFixed:c.injectables,layout:((q=(D=f.Metadata.Rendition)==null?void 0:D.Layout)!=null?q:"unknown")==="fixed"?"fixed":"reflowable"}),m=yield Er.create({mainElement:e,headerMenu:r,footerMenu:n,publication:f,settings:g,annotator:s,upLink:l,initialLastReadingPosition:c.lastReadingPosition,material:c.material,api:c.api,rights:c.rights,tts:c.tts,sample:c.sample,injectables:((k=(V=f.Metadata.Rendition)==null?void 0:V.Layout)!=null?k:"unknown")==="fixed"?c.injectablesFixed:c.injectables,attributes:c.attributes,services:c.services}),A=f.isReflowable?yield Dr.create(st({delegate:m},c.highlighter)):void 0,h=((K=c.rights)==null?void 0:K.enableBookmarks)?yield G3.create(st({annotator:s,headerMenu:r,rights:c.rights,publication:f,delegate:m,initialAnnotations:c.initialAnnotations},c.bookmarks)):void 0,b=((de=c.rights)==null?void 0:de.enableAnnotations)?yield W3.create(st({annotator:s,headerMenu:r,rights:c.rights,publication:f,delegate:m,initialAnnotations:c.initialAnnotations,highlighter:A},c.annotations)):void 0,w=(oe=c.rights)==null?void 0:oe.enableTTS,_=w?yield yF.create(st({store:o,initialTTSSettings:c.tts,headerMenu:r},c.tts)):void 0,E=w?yield vF.create(st({delegate:m,tts:_,headerMenu:r,rights:c.rights,highlighter:A},c.tts)):void 0,y=((se=c.rights)==null?void 0:se.enableSearch)?yield AF.create(st({headerMenu:r,delegate:m,publication:f,highlighter:A},c.search)):void 0,u=((ae=c.rights)==null?void 0:ae.enableTimeline)?yield oF.create({publication:f,delegate:m}):void 0,d=((ce=c.rights)==null?void 0:ce.enableContentProtection)?yield J3.create(st({delegate:m},c.protection)):void 0,v=(ee=(U=c.rights)==null?void 0:U.enableMediaOverlays)!=null?ee:!1,C=v?yield iF.create(st({store:o,initialMediaOverlaySettings:c.mediaOverlays,headerMenu:r},c.mediaOverlays)):void 0,O=v?yield aF.create(st({publication:f,settings:C,delegate:m},c.mediaOverlays)):void 0;return new p0(g,_,m,A,h,b,E,y,d,u,C,O)})}get publicationLanguage(){return this.navigator.publication.Metadata.Language}isTTSIncrementable(t){return t==="pitch"||t==="rate"||t==="volume"}isMOIncrementable(t){return t==="mo_volume"}get currentLocator(){return this.navigator.currentLocator()}get positions(){return this.navigator.positions()}};function RF(t,e){return e.isFixedLayout&&(t.rights||(t.rights={}),t.rights.enableAnnotations=!1,t.rights.enableSearch=!1,t.rights.enableTTS=!1),t}var $3=p0,pye=p0.build;var en=Ce(require("react"));var Eh=window.location.origin,MF=[{type:"style",url:`${Eh}/css/ReadiumCSS-before.css`,r2before:!0},{type:"style",url:`${Eh}/css/ReadiumCSS-default.css`,r2default:!0},{type:"style",url:`${Eh}/css/ReadiumCSS-after.css`,r2after:!0},{type:"style",url:`${Eh}/fonts/opendyslexic/opendyslexic.css`,fontFamily:"opendyslexic"}],eP=MF;function kF(t,e){var r;switch(e.type){case"SET_READER":{let n=e.reader.currentSettings();return{reader:e.reader,isScrolling:n.verticalScroll,colorMode:DF(n.appearance),fontSize:n.fontSize,fontFamily:(r=LF[n.fontFamily])!=null?r:"publisher",currentTocUrl:e.reader.mostRecentNavigatedTocItem()}}case"SET_COLOR_MODE":return ut(Ze({},t),{colorMode:e.mode});case"SET_SCROLL":return ut(Ze({},t),{isScrolling:e.isScrolling});case"SET_FONT_SIZE":return ut(Ze({},t),{fontSize:e.size});case"SET_FONT_FAMILY":return ut(Ze({},t),{fontFamily:e.family});case"SET_CURRENT_TOC_URL":return ut(Ze({},t),{currentTocUrl:e.currentTocUrl})}}var tP=4;function m0(t){let{webpubManifestUrl:e,manifest:r,getContent:n}=t!=null?t:{},[i,a]=en.default.useReducer(kF,{colorMode:"day",isScrolling:!1,fontSize:16,fontFamily:"sans-serif",reader:void 0,currentTocUrl:null}),{reader:o,fontSize:s}=i;en.default.useEffect(()=>{if(!e)return;let w=new URL(e);$3.build({url:w,injectables:eP,injectablesFixed:[],attributes:{navHeight:ea,margin:0},api:{getContent:n}}).then(_=>{a({type:"SET_READER",reader:_})})},[e,n]);let l=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=yield o.atEnd();o.nextPage(),w&&a({type:"SET_CURRENT_TOC_URL",currentTocUrl:o.mostRecentNavigatedTocItem()})}),[o]),f=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=yield o.atStart();o.previousPage(),w&&a({type:"SET_CURRENT_TOC_URL",currentTocUrl:o.mostRecentNavigatedTocItem()})}),[o]),c=en.default.useCallback(w=>le(this,null,function*(){!o||(a({type:"SET_COLOR_MODE",mode:w}),yield o.applyUserSettings({appearance:w}))}),[o]),g=en.default.useCallback(w=>le(this,null,function*(){let _=w==="scrolling";yield o==null?void 0:o.scroll(_),a({type:"SET_SCROLL",isScrolling:_})}),[o]),m=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=s+tP;yield o.applyUserSettings({fontSize:w}),a({type:"SET_FONT_SIZE",size:w})}),[o,s]),p=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=s-tP;yield o.applyUserSettings({fontSize:w}),a({type:"SET_FONT_SIZE",size:w})}),[o,s]),A=en.default.useCallback(w=>le(this,null,function*(){if(!o)return;let _=BF[w];yield o.applyUserSettings({fontFamily:_}),a({type:"SET_FONT_FAMILY",family:w})}),[o]),h=en.default.useCallback(w=>{if(!!o)try{o.goTo({href:w}),a({type:"SET_CURRENT_TOC_URL",currentTocUrl:w})}catch(_){console.error(_)}},[o]),b=!o;return!e||!r?null:b?{type:null,isLoading:!0,content:en.default.createElement(iu,null),navigator:null,manifest:null,state:null}:{type:"HTML",isLoading:!1,content:en.default.createElement(iu,null),state:i,manifest:r,navigator:{goForward:l,goBackward:f,setColorMode:c,setScroll:g,increaseFontSize:m,decreaseFontSize:p,setFontFamily:A,goToPage:h}}}function DF(t){switch(t){case"readium-default-on":return"day";case"readium-night-on":return"night";case"readium-sepia-on":return"sepia";default:return console.error("COLOR MODE SLIPPED THROUG",t),"day"}}var BF={publisher:"Original",serif:"serif","sans-serif":"sans-serif","open-dyslexic":"opendyslexic"},LF={Original:"publisher",serif:"serif","sans-serif":"sans-serif",opendyslexic:"open-dyslexic"};var rP="https://librarysimplified.org/terms/profiles/pdf",nP="stub/webpub+axisnow";function jF(t){switch(t){case nP:return"HTML";case rP:return"PDF";case void 0:return"HTML";case null:return}}function A0(t){let{webpubManifestUrl:e,getContent:r,proxyUrl:n}=t,[i,a]=Ch.default.useState(null),o=jF(i?i.metadata.conformsTo:null),s=m0(o==="HTML"&&i?{webpubManifestUrl:e,manifest:i,getContent:r}:void 0),l=Tg(o==="PDF"&&i?{webpubManifestUrl:e,manifest:i,proxyUrl:n}:void 0);if(Ch.default.useEffect(()=>{kS(e).then(a)},[e]),i===null)return{isLoading:!0,content:Ch.default.createElement(iu,null),manifest:null,navigator:null,state:null,type:null};if(s)return s;if(l)return l;throw new Error(`No reader was initialized for the webpub with url: ${e} and type: ${o}.`)}var IF=({webpubManifestUrl:t,proxyUrl:e,getContent:r})=>{let n=A0({webpubManifestUrl:t,proxyUrl:e,getContent:r}),{content:i}=n;return iP.default.createElement(MS,Ze({},n),i)},NF=IF;
606
+ `,vh=It(Ng()),CF=It(nH()),h0=It(yu());me();var Lu=class{constructor(){this.onBackwardSwipe=()=>{},this.onForwardSwipe=()=>{},this.setupEvents=t=>{var e=null,r=null,n=this;t.addEventListener("touchstart",function(i){i.changedTouches.length===1&&(e=i)},!1),t.addEventListener("touchend",function(i){if(i.changedTouches.length!==1||!e)return;let a=e.changedTouches[0],o=i.changedTouches[0];if(!a)return;let s=window.devicePixelRatio,l=(a.clientX-o.clientX)/s,f=(a.clientY-o.clientY)/s;if(Math.abs(l)<Lu.TAP_TOLERANCE&&Math.abs(f)<Lu.TAP_TOLERANCE){if(r){e=null,r=null;return}if(i.timeStamp-e.timeStamp>Lu.LONG_PRESS_MS){e=null,r=null;return}e=null,r=i;return}if(r=null,i.timeStamp-e.timeStamp>Lu.SLOW_SWIPE_MS){e=null;return}let c=(a.clientY-o.clientY)/(a.clientX-o.clientX);if(Math.abs(c)>.5){e=null;return}l<0?n.onBackwardSwipe(i):n.onForwardSwipe(i),e=null},!1)}}},yh=Lu;yh.TAP_TOLERANCE=10;yh.LONG_PRESS_MS=500;yh.SLOW_SWIPE_MS=500;me();var _F=class{constructor(){this.onBackwardSwipe=()=>{},this.onForwardSwipe=()=>{},this.setupEvents=t=>{this.focusin(t),this.keydown(t)},this.focusin=t=>{let e=this;t.addEventListener("focusin",function(r){e.delegate.view.snap(r.target)},!0)},this.keydown=t=>{let e=this;t.addEventListener("keydown",function(r){let n=r.target;if(/input|select|option|textarea/i.test(n.tagName)||!(n.ownerDocument||n).defaultView.getSelection().isCollapsed)return;switch(r.key){case"ArrowRight":e.onForwardSwipe(r);break;case"ArrowLeft":e.onBackwardSwipe(r);break}},!1)}}};me();var OF=It(yu()),SF=class{constructor(t){this.enforceSampleRead=(0,OF.debounce)(e=>{var p,A,h;let n=Math.round(e.locations.totalProgression*100)<=((p=this.delegate.sample)==null?void 0:p.limit);this.delegate.view.layout==="fixed"&&!n&&e.locations.position<=((A=this.delegate.sample)==null?void 0:A.minimum)&&(n=!0);let i={37:1,38:0,39:1,40:1,32:1,33:1,34:1,35:1,36:1};function a(b){b.preventDefault()}function o(b){i[b.keyCode]&&!n&&a(b)}let s=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){s=!0}}))}catch(b){}let l=s?{passive:!1}:!1;function f(b){b=b||window.event;let w=Math.max(-1,Math.min(1,b.wheelDelta||-b.detail));return w==1,w==-1&&!n&&b.preventDefault(),!1}let c;function g(b){b=b||window.event;let w=b.target||b.srcElement,_=b.touches[0].clientY;if(!(_>c)){if(_<c&&!n)return w.className.match(/\baltNav\b/)||(b.returnValue=!1,b.cancelable&&(b.cancelBubble=!0),b.preventDefault&&b.cancelable&&(b.preventDefault(),b.stopPropagation())),!1}return c=_,!1}function m(b){return b=b||window.event,c=b.touches[0].clientY,!1}window.addEventListener("mousewheel",f,l),window.addEventListener("DOMMouseScroll",f,l),window.addEventListener("keydown",o,l),window.addEventListener("touchmove",g,l),window.addEventListener("touchstart",m,l),n?(this.delegate.iframes[0].focus(),this.delegate.errorMessage&&(this.delegate.errorMessage.style.display="none",this.delegate.errorMessage.style.removeProperty("background-color"))):(this.delegate.iframes[0].blur(),this.delegate.errorMessage&&(this.delegate.errorMessage.style.display="block",this.delegate.errorMessage.style.backgroundColor="rgb(255, 255, 255)",this.delegate.errorMessage.innerHTML=(h=this.delegate.sample)==null?void 0:h.popup))},300),this.delegate=t}},Er=class{constructor(t,e=null,r=null,n=null,i,a,o,s,l,f,c,g,m){this.iframes=[],this.sideNavExpanded=!1,this.material=!1,this.currentChapterLink={},this.currentSpreadLinks={},this.upLink=null,this.didInitKeyboardEventHandler=!1,this.onResize=()=>{clearTimeout(this.timeout),this.timeout=setTimeout(this.handleResize.bind(this),200)},this.reload=()=>le(this,null,function*(){let p=null;if(this.annotator&&(p=yield this.annotator.getLastReadingPosition()),p){let A=this.publication.getAbsoluteHref(p.href);_e&&console.log(p.href),_e&&console.log(A),p.href=A,yield this.navigate(p)}}),this.savePosition=(0,h0.debounce)(()=>le(this,null,function*(){this.annotator&&(yield this.saveCurrentReadingPosition())}),200),this.checkResourcePosition=(0,h0.debounce)(()=>{var p,A,h,b,w,_;this.view.atStart()&&this.view.atEnd()?((p=this.api)==null?void 0:p.resourceFitsScreen)&&((A=this.api)==null||A.resourceFitsScreen()):this.view.atEnd()?((h=this.api)==null?void 0:h.resourceAtEnd)&&((b=this.api)==null||b.resourceAtEnd()):this.view.atStart()&&((w=this.api)==null?void 0:w.resourceAtStart)&&((_=this.api)==null||_.resourceAtStart())},200),this.settings=t,this.annotator=e,this.view=t.view,this.view.attributes=c,this.view.delegate=this,this.eventHandler=new mH,this.touchEventHandler=new yh,this.keyboardEventHandler=new _F,this.upLinkConfig=r,this.initialLastReadingPosition=n,this.publication=i,this.material=a,this.api=o,this.rights=s,this.tts=l,this.injectables=f,this.attributes=c||{margin:0},this.services=g,this.sample=m,this.sampleReadEventHandler=new SF(this)}static create(t){return le(this,null,function*(){let e=new this(t.settings,t.annotator||null,t.upLink||null,t.initialLastReadingPosition||null,t.publication,t.material,t.api,t.rights,t.tts,t.injectables,t.attributes||{margin:0},t.services,t.sample);return yield e.start(t.mainElement,t.headerMenu,t.footerMenu),new Promise(r=>r(e))})}stop(){var t;_e&&console.log("Iframe navigator stop"),Ge(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),Ge(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),Ge(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Ge(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),Ge(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Ge(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),Ge(this.tryAgainButton,"click",this.tryAgain.bind(this)),Ge(this.goBackButton,"click",Er.goBack.bind(this)),Ge(this.bookmarksControl,"keydown",this.hideBookmarksOnEscape.bind(this)),Ge(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),Ge(window,"resize",this.onResize),this.iframes.forEach(e=>{Ge(e,"resize",this.onResize)}),((t=this.rights)==null?void 0:t.enableMaterial)&&(this.mDropdowns&&this.mDropdowns.forEach(e=>{e.destroy()}),this.mCollapsibles&&this.mCollapsibles.forEach(e=>{e.destroy()}),this.mSidenav&&this.mSidenav.destroy(),this.mTabs&&this.mTabs.forEach(e=>{e.destroy()}))}start(t,e,r){return le(this,null,function*(){var p,A,h,b,w,_,E,y,u;this.headerMenu=e,this.mainElement=t;try{let d=rr(t,"main#iframe-wrapper");d.style.overflow="overlay";let v=Le(t,"main#iframe-wrapper iframe"),C=Le(t,"#second");if(v&&this.iframes.push(v),C&&this.iframes.push(C),window.matchMedia("screen and (max-width: 600px)").matches&&(this.settings.columnCount=1),this.iframes.length===0){d.style.overflow="overlay";let O=document.createElement("iframe");if(O.setAttribute("SCROLLING","no"),O.setAttribute("allowtransparency","true"),this.iframes.push(O),this.publication.isFixedLayout?(this.spreads=document.createElement("div"),this.firstSpread=document.createElement("div"),this.spreads.style.display="flex",this.spreads.style.alignItems="center",this.spreads.style.justifyContent="center",this.spreads.appendChild(this.firstSpread),this.firstSpread.appendChild(this.iframes[0]),d.appendChild(this.spreads)):(O.setAttribute("height","100%"),O.setAttribute("width","100%"),d.appendChild(this.iframes[0])),this.publication.isFixedLayout)if(this.settings.columnCount!==1){let x=document.createElement("div");this.spreads.appendChild(x);let R=document.createElement("iframe");R.setAttribute("SCROLLING","no"),R.setAttribute("allowtransparency","true"),R.style.opacity="1",R.style.border="none",R.style.overflow="hidden",this.iframes.push(R),x.appendChild(this.iframes[1]),this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 100% 120%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc",x.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, 0% 120%)",x.style.boxShadow="0 0 8px 2px #ccc"}else this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc";else this.iframes[0].style.paddingTop=((A=(p=this.attributes)==null?void 0:p.iframePaddingTop)!=null?A:0)+"px"}if(this.publication.isFixedLayout){let O=d.clientHeight;var n=this.iframes[0].parentElement.parentElement;n.style.height=O+40+"px"}else this.iframes.length===2&&this.iframes.pop();this.loadingMessage=Le(t,"#reader-loading"),this.loadingMessage&&(this.loadingMessage.innerHTML=wF,this.loadingMessage.style.display="none"),this.errorMessage=Le(t,"#reader-error"),this.errorMessage&&(this.errorMessage.innerHTML=EF,this.errorMessage.style.display="none"),this.tryAgainButton=Le(t,"button[class=try-again]"),this.goBackButton=Le(t,"button[class=go-back]"),this.infoTop=Le(t,"div[class='info top']"),this.infoBottom=Le(t,"div[class='info bottom']"),this.headerMenu&&(this.bookTitle=Le(this.headerMenu,"#book-title")),this.infoBottom&&(this.chapterTitle=Le(this.infoBottom,"span[class=chapter-title]")),this.infoBottom&&(this.chapterPosition=Le(this.infoBottom,"span[class=chapter-position]")),this.infoBottom&&(this.remainingPositions=Le(this.infoBottom,"span[class=remaining-positions]")),this.headerMenu&&(this.espandMenuIcon=Le(this.headerMenu,"#expand-menu")),this.headerMenu&&(this.links=Le(this.headerMenu,"ul.links.top")),this.headerMenu&&(this.linksTopLeft=Le(this.headerMenu,"#nav-mobile-left")),this.headerMenu&&(this.tocView=Le(this.headerMenu,"#container-view-toc")),this.headerMenu&&(this.landmarksView=Le(e,"#container-view-landmarks")),this.headerMenu&&(this.landmarksSection=Le(e,"#sidenav-section-landmarks")),this.headerMenu&&(this.pageListView=Le(e,"#container-view-pagelist")),this.headerMenu&&(this.goToPageView=Le(e,"#sidenav-section-gotopage")),this.headerMenu&&(this.goToPageNumberInput=Le(e,"#goToPageNumberInput")),this.headerMenu&&(this.goToPageNumberButton=Le(e,"#goToPageNumberButton")),r&&(this.linksBottom=Le(r,"ul.links.bottom")),r&&(this.linksMiddle=Le(r,"ul.links.middle")),this.headerMenu&&(this.nextChapterAnchorElement=Le(this.headerMenu,"a[rel=next]")),this.headerMenu&&(this.nextChapterBottomAnchorElement=Le(t,"#next-chapter")),r&&(this.nextPageAnchorElement=Le(r,"a[rel=next]")),this.headerMenu&&(this.previousChapterAnchorElement=Le(this.headerMenu,"a[rel=prev]")),this.headerMenu&&(this.previousChapterTopAnchorElement=Le(t,"#previous-chapter")),r&&(this.previousPageAnchorElement=Le(r,"a[rel=prev]")),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.newPosition=null,this.newElementId=null,this.isBeingStyled=!0,this.isLoading=!0,this.setupEvents(),this.settings.setIframe(this.iframes[0]),this.settings.onSettingsChange(this.handleResize.bind(this)),this.settings.onColumnSettingsChange(this.handleNumberOfIframes.bind(this)),this.settings.onViewChange(this.updateBookView.bind(this)),this.initialLastReadingPosition&&this.annotator.initLastReadingPosition(this.initialLastReadingPosition);var i=this;if(this.headerMenu)var a=Le(this.headerMenu,"#menu-button-search"),o=Le(this.headerMenu,"#menu-button-tts"),s=Le(this.headerMenu,"#menu-button-bookmark"),l=Le(this.headerMenu,"#menu-button-play"),f=Le(this.headerMenu,"#menu-button-pause"),c=Le(this.headerMenu,"#menu-button-mediaoverlay");if((h=this.rights)==null?void 0:h.enableMaterial){let O=document.querySelectorAll(".sidenav");O&&(i.mSidenav=vh.Sidenav.init(O,{edge:(w=(b=this.attributes)==null?void 0:b.sideNavPosition)!=null?w:"left"}));let x=document.querySelectorAll(".collapsible");x&&(i.mCollapsibles=vh.Collapsible.init(x,{accordion:!0}));let R=document.querySelectorAll(".dropdown-trigger");R&&(i.mDropdowns=vh.Dropdown.init(R,{alignment:"right",constrainWidth:!1,coverTrigger:!1,closeOnClick:!1,autoTrigger:!1,onOpenEnd:function(){i.mTabs.forEach(T=>{T.updateTabIndicator()})}}));let z=document.querySelectorAll(".tabs");if(z&&(i.mTabs=vh.Tabs.init(z)),this.headerMenu){if(!((_=this.rights)==null?void 0:_.enableBookmarks)){s&&s.parentElement.style.setProperty("display","none");var g=Le(this.headerMenu,"#sidenav-section-bookmarks");g&&g.style.setProperty("display","none")}if(!((E=this.rights)==null?void 0:E.enableAnnotations)){var m=Le(this.headerMenu,"#sidenav-section-highlights");m&&m.style.setProperty("display","none")}((y=this.rights)==null?void 0:y.enableTTS)||o&&o.parentElement.style.setProperty("display","none"),((u=this.rights)==null?void 0:u.enableSearch)||a&&a.parentElement.style.setProperty("display","none"),a&&this.view.delegate.publication.isFixedLayout&&a.parentElement.style.setProperty("display","none")}}else this.headerMenu&&(a&&a.parentElement.style.setProperty("display","none"),o&&o.parentElement.style.setProperty("display","none"),s&&s.parentElement.style.setProperty("display","none"));return this.hasMediaOverlays?(l&&l.parentElement.style.setProperty("display","block"),f&&f.parentElement.style.setProperty("display","block"),c&&c.parentElement.style.setProperty("display","block")):(l&&l.parentElement.style.setProperty("display","none"),f&&f.parentElement.style.setProperty("display","none"),c&&c.parentElement.style.setProperty("display","none")),yield this.loadManifest()}catch(d){return console.error(d),this.abortOnError(),Promise.reject(d)}})}setupEvents(){for(let t of this.iframes)Re(t,"load",this.handleIFrameLoad.bind(this));Re(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),Re(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),Re(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Re(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),Re(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Re(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),Re(this.tryAgainButton,"click",this.tryAgain.bind(this)),Re(this.goBackButton,"click",Er.goBack.bind(this)),Re(this.bookmarksControl,"keydown",this.hideBookmarksOnEscape.bind(this)),Re(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),Re(this.goToPageNumberInput,"keypress",this.goToPageNumber.bind(this)),Re(this.goToPageNumberButton,"click",this.goToPageNumber.bind(this)),Re(window,"resize",this.onResize);for(let t of this.iframes)Re(t,"resize",this.onResize)}setupModalFocusTrap(t,e,r){let n=9;e.addEventListener("keydown",i=>{if(Er.isDisplayed(t)){let a=i.keyCode===n,o=!!i.shiftKey;a&&o&&(r.focus(),i.preventDefault(),i.stopPropagation())}}),r.addEventListener("keydown",i=>{if(Er.isDisplayed(t)){let a=i.keyCode===n,o=!!i.shiftKey;a&&!o&&(e.focus(),i.preventDefault(),i.stopPropagation())}})}goToPageNumber(t){return le(this,null,function*(){if(this.goToPageNumberInput.value&&(t.key==="Enter"||t.type==="click")){var e=this.publication.pageList.filter(n=>n.href.slice(n.href.indexOf("#")+1).replace(/[^0-9]/g,"")===this.goToPageNumberInput.value);if(e&&e.length>0){var r=e[0];let n={progression:0};if(r.Href.indexOf("#")!==-1){let a=r.Href.slice(r.Href.indexOf("#")+1);a!==null&&(n={fragment:a})}let i={href:this.publication.getAbsoluteHref(r.Href),locations:n,type:r.TypeLink,title:r.Title};this.stopReadAloud(!0),this.navigate(i)}}})}updateBookView(){this.view.layout==="fixed"?(this.nextPageAnchorElement&&(this.nextPageAnchorElement.style.display="none"),this.previousPageAnchorElement&&(this.previousPageAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")):(this.settings.isPaginated().then(t=>{if(t)this.view.height=_u()-40-this.attributes.margin,this.infoBottom&&this.infoBottom.style.removeProperty("display"),document.body.onscroll=()=>{},this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextPageAnchorElement&&(this.nextPageAnchorElement.style.display="unset"),this.previousPageAnchorElement&&(this.previousPageAnchorElement.style.display="unset"),this.chapterTitle&&(this.chapterTitle.style.display="inline"),this.chapterPosition&&(this.chapterPosition.style.display="inline"),this.remainingPositions&&(this.remainingPositions.style.display="inline"),this.eventHandler&&(this.eventHandler.onInternalLink=this.handleInternalLink.bind(this),this.eventHandler.onClickThrough=this.handleClickThrough.bind(this)),this.touchEventHandler&&(this.touchEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.touchEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this)),this.keyboardEventHandler&&(this.keyboardEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.keyboardEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this));else{this.infoBottom&&(this.infoBottom.style.display="none"),this.nextPageAnchorElement&&(this.nextPageAnchorElement.style.display="none"),this.previousPageAnchorElement&&(this.previousPageAnchorElement.style.display="none"),this.view.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")):this.view.atStart()&&this.view.atEnd()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):this.view.atEnd()?(this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset")):this.view.atStart()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"));let e=(0,h0.debounce)(()=>{this.isScrolling=!1},200),r=rr(document,"#iframe-wrapper");r.onscroll=()=>le(this,null,function*(){this.isScrolling=!0,yield this.savePosition(),this.view.atEnd(),this.view.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")):(this.settings.isPaginated().then(n=>{n||(this.view.atStart()&&this.view.atEnd()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):this.view.atEnd()?(this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset")):this.view.atStart()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")))}),this.checkResourcePosition()),e()}),this.chapterTitle&&(this.chapterTitle.style.display="none"),this.chapterPosition&&(this.chapterPosition.style.display="none"),this.remainingPositions&&(this.remainingPositions.style.display="none"),this.eventHandler&&(this.eventHandler.onInternalLink=this.handleInternalLink.bind(this),this.eventHandler.onClickThrough=this.handleClickThrough.bind(this)),this.touchEventHandler&&(this.touchEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.touchEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this)),this.keyboardEventHandler&&(this.keyboardEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.keyboardEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this))}}),setTimeout(()=>le(this,null,function*(){var t;if(this.annotationModule!==void 0)yield this.annotationModule.drawHighlights();else if(((t=this.rights)==null?void 0:t.enableSearch)&&this.searchModule!==void 0&&this.highlighter!==void 0){for(let e of this.iframes)yield this.highlighter.destroyAllhighlights(e.contentDocument);this.searchModule.drawSearch()}}),200))}loadManifest(){return le(this,null,function*(){try{let e=(l,f,c,g=!1)=>{var m,p;c&&(m=c,l instanceof HTMLDivElement&&(p=l));var A=document.createElement("ul");g&&(A=document.createElement("ol")),A.className="sidenav-toc";let h=null;for(let b of f){let w=document.createElement("li"),_=document.createElement("a"),E=document.createElement("span");_.className="chapter-link",_.tabIndex=-1;let y="";b.Href?(y=this.publication.getAbsoluteHref(b.Href),_.href=y,_.innerHTML=b.Title||"",w.appendChild(_)):(E.innerHTML=b.Title||"",E.className="chapter-title",w.appendChild(E)),b.Children&&b.Children.length>0&&e(w,b.Children,null,!0),A.appendChild(w),h=_}h&&m&&this.setupModalFocusTrap(p,m,h),Re(A,"click",b=>{if(b.preventDefault(),b.stopPropagation(),b.target&&b.target.tagName.toLowerCase()==="a"){let w=b.target;if(w.className.indexOf("active")!==-1)this.hideView(p,m);else{m==null||m.focus();let _={progression:0};if(w.href.indexOf("#")!==-1){let y=w.href.slice(w.href.indexOf("#")+1);y!==null&&(_={fragment:y})}let E={href:w.href,locations:_,type:w.type,title:w.title};this.hideView(p,m),this.navigate(E)}}}),l.appendChild(A)},r=this.publication.tableOfContents,n=this.publication.landmarks,i=this.publication.pageList;if(this.tocView&&(r.length?e(this.tocView,r):this.tocView.parentElement.parentElement.removeChild(this.tocView.parentElement)),this.pageListView&&((i==null?void 0:i.length)?e(this.pageListView,i):this.pageListView.parentElement.parentElement.removeChild(this.pageListView.parentElement)),this.goToPageView&&((i==null?void 0:i.length)||this.goToPageView.parentElement.removeChild(this.goToPageView)),this.landmarksView&&((n==null?void 0:n.length)?e(this.landmarksView,n):this.landmarksSection.parentElement.removeChild(this.landmarksSection)),(this.links||this.linksTopLeft)&&this.upLinkConfig&&this.upLinkConfig.url){let l=this.upLinkConfig.url,f=this.upLinkConfig.label||"",c=this.upLinkConfig.ariaLabel||f;var t=bF(l.href,f,c);let g=document.createElement("li");g.classList.add("uplink-wrapper"),g.innerHTML=t,this.links?(this.links.insertBefore(g,this.links.firstChild),this.upLink=rr(this.links,"a[rel=up]")):(this.linksTopLeft.insertBefore(g,this.linksTopLeft.firstChild),this.upLink=rr(this.linksTopLeft,"a[rel=up]"))}let a=null;this.annotator&&(a=yield this.annotator.getLastReadingPosition());let o=this.publication.getStartLink(),s=null;if(o&&o.Href&&(s=this.publication.getAbsoluteHref(o.Href)),a){let l=this.publication.getAbsoluteHref(a.href);_e&&console.log(a.href),_e&&console.log(l),a.href=l,yield this.navigate(a)}else if(s){let l={href:s,locations:{progression:0},created:new Date,title:o.Title};yield this.navigate(l)}return new Promise(l=>l())}catch(e){return console.error(e),this.abortOnError(),new Promise((r,n)=>n(e)).catch(()=>{})}})}handleIFrameLoad(){return le(this,null,function*(){var n,i,a,o,s;this.errorMessage&&(this.errorMessage.style.display="none"),this.showLoadingMessageAfterDelay();try{let l=0;this.newPosition&&(l=this.newPosition.locations.progression),this.handleResize(),this.updateBookView(),yield this.settings.applyProperties();let f=this.currentChapterLink.href,c=this.publication.getPreviousSpineItem(f);c&&c.Href&&(this.previousChapterLink={href:c.Href,title:c.Title,type:c.TypeLink}),this.previousChapterAnchorElement&&(this.previousChapterLink?(this.previousChapterAnchorElement.href=this.publication.getAbsoluteHref(this.previousChapterLink.href),this.previousChapterAnchorElement.className=this.previousChapterAnchorElement.className.replace(" disabled","")):(this.previousChapterAnchorElement.removeAttribute("href"),this.previousChapterAnchorElement.className+=" disabled"));let g=this.publication.getNextSpineItem(f);g?this.nextChapterLink={href:g.Href,title:g.Title,type:g.TypeLink}:this.nextChapterLink=void 0,this.nextChapterAnchorElement&&(this.nextChapterLink?(this.nextChapterAnchorElement.href=this.publication.getAbsoluteHref(this.nextChapterLink.href),this.nextChapterAnchorElement.className=this.nextChapterAnchorElement.className.replace(" disabled","")):(this.nextChapterAnchorElement.removeAttribute("href"),this.nextChapterAnchorElement.className+=" disabled")),this.currentTocUrl!==null?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(f),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let m=this.publication.getSpineItem(f);m!==null&&(this.currentChapterLink.title=m.Title,this.currentChapterLink.type=m.TypeLink);let p=this.publication.getTOCItem(f);this.currentTocUrl!==null&&(p=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&p!==null&&p.Title&&(this.currentChapterLink.title=p.Title),!this.currentChapterLink.type&&p!==null&&p.TypeLink&&(this.currentChapterLink.title=p.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),yield this.injectInjectablesIntoIframeHead(),this.highlighter!==void 0&&(yield this.highlighter.initialize());let A=this.iframes[0].contentDocument.body;if(((n=this.rights)==null?void 0:n.enableTTS)&&((i=this.tts)==null?void 0:i.enableSplitter)&&(0,CF.default)({target:A,by:"lines"}),((a=this.rights)==null?void 0:a.enableContentProtection)&&this.contentProtectionModule!==void 0&&(yield this.contentProtectionModule.initialize()),this.eventHandler){for(let h of this.iframes)this.eventHandler.setupEvents(h.contentDocument),this.touchEventHandler.setupEvents(h.contentDocument),this.keyboardEventHandler.setupEvents(h.contentDocument);this.touchEventHandler.setupEvents(this.errorMessage),this.didInitKeyboardEventHandler||(this.keyboardEventHandler.delegate=this,this.keyboardEventHandler.keydown(document),this.didInitKeyboardEventHandler=!0)}if(this.view.layout!=="fixed"&&((o=this.view)==null?void 0:o.isScrollMode()))for(let h of this.iframes)this.view.setIframeHeight(h);if(this.annotationModule!==void 0&&(yield this.annotationModule.initialize()),(s=this.rights)==null?void 0:s.enableTTS)for(let h of this.iframes){let b=h.contentDocument.body;this.ttsModule!==void 0&&(yield this.ttsModule.initialize(b))}for(let h of this.iframes)for(var t=h.contentDocument.body.querySelectorAll('[*|type="pagebreak"]'),e=0;e<t.length;e++){var r=t[e];_e&&console.log(r),r.innerHTML.length===0&&(r.innerHTML=r.getAttribute("title")),r.className="epubPageBreak"}return this.timelineModule!==void 0&&(yield this.timelineModule.initialize()),this.mediaOverlayModule!==void 0&&(yield this.mediaOverlayModule.initialize()),setTimeout(()=>le(this,null,function*(){if(this.newElementId){let h=this.iframes[0].contentDocument.getElementById(this.newElementId);this.view.goToElement(h),this.newElementId=null}else this.newPosition&&this.newPosition.highlight?this.view.goToCssSelector(this.newPosition.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector):l>0&&this.view.goToPosition(l);this.newPosition=null,this.hideLoadingMessage(),this.showIframeContents(),yield this.updatePositionInfo()}),200),Promise.resolve()}catch(l){return console.error(l),this.abortOnError(),Promise.reject(l)}})}injectInjectablesIntoIframeHead(){return le(this,null,function*(){let t=[],e=r=>{let n=new Promise(i=>{r.onload=()=>{i(!0)}});t.push(n)};for(let r of this.iframes){let n=r.contentDocument.head;n&&(n.insertBefore(Er.createBase(this.currentChapterLink.href),n.firstChild),this.injectables.forEach(i=>{if(i.type==="style")if(i.fontFamily){if(this.settings.initAddedFont(),!i.systemFont){let a=Er.createCssLink(i.url);n.appendChild(a),e(a)}}else if(i.r2before){let a=Er.createCssLink(i.url);n.insertBefore(a,n.firstChild),e(a)}else if(i.r2default){let a=Er.createCssLink(i.url);n.insertBefore(a,n.childNodes[1]),e(a)}else if(i.r2after){i.appearance&&this.settings.initAddedAppearance();let a=Er.createCssLink(i.url);n.appendChild(a),e(a)}else{let a=Er.createCssLink(i.url);n.appendChild(a),e(a)}else if(i.type==="script"){let a=Er.createJavascriptLink(i.url,i.async);n.appendChild(a),e(a)}}))}t.length!==0&&(yield Promise.all(t))})}abortOnError(){this.errorMessage&&(this.errorMessage.style.display="block"),this.isLoading&&this.hideLoadingMessage()}tryAgain(){this.precessContentForIframe()}precessContentForIframe(){var s,l,f,c,g,m;let t=this;var e=this.publication.getSpineIndex(this.currentChapterLink.href),r=e%2==1;this.showLoadingMessageAfterDelay();function n(p,A){let b=new DOMParser().parseFromString(p,"application/xhtml+xml");b.head&&b.head.insertBefore(Er.createBase(A),b.head.firstChild);let w=b.documentElement.outerHTML,_=t.iframes[0].contentDocument;_.open(),_.write(w),_.close()}function i(p,A){let b=new DOMParser().parseFromString(p,"application/xhtml+xml");b.head&&b.head.insertBefore(Er.createBase(A),b.head.firstChild);let w=b.documentElement.outerHTML,_=t.iframes[1].contentDocument;_.open(),_.write(w),_.close()}let a=new URL(this.currentChapterLink.href),o=window.location.protocol===a.protocol&&window.location.port===a.port&&window.location.hostname===a.hostname;if((s=this.api)==null?void 0:s.getContent)if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(this.currentSpreadLinks.left={href:this.currentChapterLink.href},(l=this.api)==null||l.getContent(this.currentChapterLink.href).then(p=>{p===void 0?o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){n.call(this,A,this.currentChapterLink.href)})):n.call(this,p,this.currentChapterLink.href)}),this.iframes.length===2)if(e<this.publication.readingOrder.length-1){let p=this.publication.getNextSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.right={href:A},(f=this.api)==null||f.getContent(A).then(h=>{h===void 0?o?this.iframes[1].src=A:fetch(A).then(b=>b.text()).then(b=>le(this,null,function*(){i.call(this,b,A),this.currentSpreadLinks.right={href:A}})):i.call(this,h,A)})}else this.iframes[1].src="about:blank"}else{if(e>0){let p=this.publication.getPreviousSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.left={href:A},(c=this.api)==null||c.getContent(A).then(h=>{h===void 0?o?this.iframes[0].src=A:fetch(A).then(b=>b.text()).then(b=>le(this,null,function*(){n.call(this,b,A)})):n.call(this,h,A)})}else this.iframes[0].src="about:blank";this.iframes.length===2&&this.publication.isFixedLayout&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},this.api.getContent(this.currentChapterLink.href).then(p=>{p===void 0?o?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){i.call(this,A,this.currentChapterLink.href)})):i.call(this,p,this.currentChapterLink.href)}))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},(g=this.api)==null||g.getContent(this.currentChapterLink.href).then(p=>{p===void 0?o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){n.call(this,A,this.currentChapterLink.href)})):n.call(this,p,this.currentChapterLink.href)});else(m=this.api)==null||m.getContent(this.currentChapterLink.href).then(p=>{this.currentSpreadLinks.left={href:this.currentChapterLink.href},p===void 0?o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(A=>A.text()).then(A=>le(this,null,function*(){n.call(this,A,this.currentChapterLink.href)})):n.call(this,p,this.currentChapterLink.href)});else if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(o){if(this.iframes[0].src=this.currentChapterLink.href,this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.iframes.length===2)if(e<this.publication.readingOrder.length-1){let p=this.publication.getNextSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.iframes[1].src=A,this.currentSpreadLinks.right={href:A}}else this.iframes[1].src="about:blank"}else if(fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){n.call(this,p,this.currentChapterLink.href)})),this.iframes.length===2)if(e<this.publication.readingOrder.length-1){let p=this.publication.getNextSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.right={href:A},fetch(A).then(h=>h.text()).then(h=>le(this,null,function*(){i.call(this,h,A)}))}else this.iframes[1].src="about:blank"}else{if(e>0){let p=this.publication.getPreviousSpineItem(this.currentChapterLink.href),A=this.publication.getAbsoluteHref(p.Href);this.currentSpreadLinks.left={href:A},o?(this.iframes[0].src=A,this.iframes.length===2&&(this.iframes[1].src=this.currentChapterLink.href)):(fetch(A).then(h=>h.text()).then(h=>le(this,null,function*(){n.call(this,h,A)})),this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},fetch(this.currentChapterLink.href).then(h=>h.text()).then(h=>le(this,null,function*(){i.call(this,h,this.currentChapterLink.href)}))))}else this.iframes[0].src="about:blank";this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},o?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){i.call(this,p,this.currentChapterLink.href)})))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){n.call(this,p,this.currentChapterLink.href)}));else this.currentSpreadLinks.left={href:this.currentChapterLink.href},o?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href).then(p=>p.text()).then(p=>le(this,null,function*(){n.call(this,p,this.currentChapterLink.href)}));this.publication.isFixedLayout&&setTimeout(()=>{let p=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).height,A=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).width;if(parseInt(p.replace("px",""))===0||parseInt(A.replace("px",""))===0){let u=dr(e===0&&this.iframes.length===2?this.iframes[1].contentDocument:this.iframes[0].contentDocument,"head");if(u){let d=Le(u,"meta[name=viewport]");if(d){var h=d.content,b=h.split(",").reduce((v,C)=>{var[O,x]=C.match(/[^\s;=]+/g);return v[O]=isNaN(Number(x))?x:+x,v},{});p=b.height+"px",A=b.width+"px"}}}var w=e===0&&this.iframes.length===2?this.iframes[1].parentElement.parentElement:this.iframes[0].parentElement.parentElement,_=(parseInt(getComputedStyle(w).width)-100)/(this.iframes.length===2?parseInt(A.replace("px",""))*2+200:parseInt(A.replace("px",""))),E=(parseInt(getComputedStyle(w).height)-100)/parseInt(p.replace("px","")),y=Math.min(_,E);w.style.transform="scale("+y+")";for(let u of this.iframes)u.style.height=p,u.style.width=A,u.parentElement.style.height=p},400)}static goBack(){window.history.back()}static isDisplayed(t){return t?t.className.indexOf(" active")!==-1:!1}static showElement(t,e){if(t){if(t.className=t.className.replace(" inactive",""),t.className.indexOf(" active")===-1&&(t.className+=" active"),t.setAttribute("aria-hidden","false"),e){e.setAttribute("aria-expanded","true");let i=e.querySelector(".icon.open");if(i&&(i.getAttribute("class")||"").indexOf(" inactive-icon")===-1){let o=(i.getAttribute("class")||"")+" inactive-icon";i.setAttribute("class",o)}let a=e.querySelector(".icon.close");if(a){let o=(a.getAttribute("class")||"").replace(" inactive-icon","");a.setAttribute("class",o)}}let r=Array.prototype.slice.call(t.querySelectorAll("button")),n=Array.prototype.slice.call(t.querySelectorAll("a"));for(let i of r)i.tabIndex=0;for(let i of n)i.tabIndex=0}}static hideElement(t,e){if(t){if(t.className=t.className.replace(" active",""),t.className.indexOf(" inactive")===-1&&(t.className+=" inactive"),t.setAttribute("aria-hidden","true"),e){e.setAttribute("aria-expanded","false");let i=e.querySelector(".icon.open");if(i){let o=(i.getAttribute("class")||"").replace(" inactive-icon","");i.setAttribute("class",o)}let a=e.querySelector(".icon.close");if(a&&(a.getAttribute("class")||"").indexOf(" inactive-icon")===-1){let o=(a.getAttribute("class")||"")+" inactive-icon";a.setAttribute("class",o)}}let r=Array.prototype.slice.call(t.querySelectorAll("button")),n=Array.prototype.slice.call(t.querySelectorAll("a"));for(let i of r)i.tabIndex=-1;for(let i of n)i.tabIndex=-1}}hideModal(t,e){for(let r of this.iframes)r.setAttribute("aria-hidden","false");this.upLink&&this.upLink.setAttribute("aria-hidden","false"),this.linksBottom&&this.linksBottom.setAttribute("aria-hidden","false"),this.linksMiddle&&this.linksMiddle.setAttribute("aria-hidden","false"),this.loadingMessage&&this.loadingMessage.setAttribute("aria-hidden","false"),this.errorMessage&&this.errorMessage.setAttribute("aria-hidden","false"),this.infoTop&&this.infoTop.setAttribute("aria-hidden","false"),this.infoBottom&&this.infoBottom.setAttribute("aria-hidden","false"),Er.hideElement(t,e)}handleEditClick(t){var e=t.target,r=Le(this.headerMenu,".sidenav");e.className.indexOf(" active")===-1?(e.className+=" active",r.className+=" expanded",e.innerText="unfold_less",this.sideNavExpanded=!0,this.bookmarkModule.showBookmarks(),this.annotationModule.showHighlights()):(e.className=e.className.replace(" active",""),r.className=r.className.replace(" expanded",""),e.innerText="unfold_more",this.sideNavExpanded=!1,this.bookmarkModule.showBookmarks(),this.annotationModule.showHighlights()),t.preventDefault(),t.stopPropagation()}get hasMediaOverlays(){return this.publication.hasMediaOverlays}startReadAloud(){var t,e;((t=this.rights)==null?void 0:t.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.startReadAloud():((e=this.rights)==null?void 0:e.enableTTS)&&this.highlighter.speakAll()}stopReadAloud(t=!1){var e,r,n;t?((e=this.rights)==null?void 0:e.enableTTS)&&this.highlighter.stopReadAloud():((r=this.rights)==null?void 0:r.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.stopReadAloud():((n=this.rights)==null?void 0:n.enableTTS)&&this.highlighter.stopReadAloud()}pauseReadAloud(){var t,e;((t=this.rights)==null?void 0:t.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.pauseReadAloud():((e=this.rights)==null?void 0:e.enableTTS)&&this.ttsModule.speakPause()}resumeReadAloud(){var t,e;((t=this.rights)==null?void 0:t.enableMediaOverlays)&&this.publication.hasMediaOverlays?this.mediaOverlayModule.resumeReadAloud():((e=this.rights)==null?void 0:e.enableTTS)&&this.ttsModule.speakResume()}totalResources(){return this.publication.readingOrder.length}mostRecentNavigatedTocItem(){return this.publication.getRelativeHref(this.currentTOCRawLink)}currentResource(){let t=this.currentChapterLink.href;return this.publication.getSpineIndex(t)}currentLink(){if(this.settings.columnCount!==1&&this.currentSpreadLinks.left!==void 0&&this.currentSpreadLinks.right!==void 0){let e=this.publication.getSpineItem(this.currentSpreadLinks.left.href),r=this.publication.getSpineItem(this.currentSpreadLinks.right.href);return[e,r]}let t=this.currentChapterLink.href;return[this.publication.getSpineItem(t)]}tableOfContents(){return this.publication.tableOfContents}readingOrder(){return this.publication.readingOrder}atStart(){return this.view.atStart()}atEnd(){return this.view.atEnd()}previousPage(){this.handlePreviousPageClick(null)}nextPage(){this.handleNextPageClick(null)}previousResource(){this.handlePreviousChapterClick(null)}nextResource(){this.handleNextChapterClick(null)}goTo(t){var i;let e=(i=t.locations)!=null?i:{progression:0};if(t.href.indexOf("#")!==-1){let a=t.href.slice(t.href.indexOf("#")+1);a!==null&&(e=fn(st({},e),{fragment:a}))}let r=st({},t);r.locations=e;let n=this.publication.getAbsoluteHref(t.href);_e&&console.log(t.href),_e&&console.log(n),r.href=n,this.stopReadAloud(!0),this.navigate(r)}currentLocator(){var r,n;let t;if(((n=(r=this.rights)==null?void 0:r.autoGeneratePositions)!=null?n:!1)&&this.publication.positions||this.publication.positions){let i=this.publication.positionsByHref(this.publication.getRelativeHref(this.currentChapterLink.href)),a=Math.ceil(this.view.getCurrentPosition()*(i.length-1));t=i[a]}else{var e=this.publication.getTOCItem(this.currentChapterLink.href);this.currentTocUrl!==null&&(e=this.publication.getTOCItem(this.currentTocUrl)),e===null&&(e=this.publication.getTOCItemAbsolute(this.currentChapterLink.href)),t={href:e.Href,type:this.currentChapterLink.type,title:this.currentChapterLink.title,locations:{}}}return t.locations.progression=this.view.getCurrentPosition(),t.displayInfo={resourceScreenIndex:Math.round(this.view.getCurrentPage()),resourceScreenCount:Math.round(this.view.getPageCount())},t}positions(){return this.publication.positions?this.publication.positions:[]}goToPosition(t){if(this.publication.positions){let e=this.publication.positions.filter(r=>r.locations.position===parseInt(String(t)))[0];this.goTo(e)}}snapToElement(t){this.view.snap(t)}applyAttributes(t){this.attributes=t,this.view.attributes=t,this.handleResize()}handlePreviousPageClick(t){this.stopReadAloud(!0),this.view.layout==="fixed"?this.handlePreviousChapterClick(t):(this.view.atStart()?this.handlePreviousChapterClick(t):(this.view.goToPreviousPage(),this.updatePositionInfo(),this.savePosition()),t&&(t.preventDefault(),t.stopPropagation()))}handleNextPageClick(t){var r,n,i,a,o,s;let e=!0;if(((r=this.sample)==null?void 0:r.isSampleRead)&&this.publication.positions){let l=this.currentLocator();e=Math.round(l.locations.totalProgression*100)<=((n=this.sample)==null?void 0:n.limit),this.view.layout==="fixed"&&!e&&l.locations.position<=((i=this.sample)==null?void 0:i.minimum)&&(e=!0)}(e&&((a=this.sample)==null?void 0:a.isSampleRead)&&this.publication.positions||!((o=this.sample)==null?void 0:o.isSampleRead)||!this.publication.positions)&&(this.stopReadAloud(!0),this.view.layout==="fixed"?this.handleNextChapterClick(t):(this.view.atEnd()?this.handleNextChapterClick(t):(this.view.goToNextPage(),this.updatePositionInfo(),this.savePosition()),t&&(t.preventDefault(),t.stopPropagation()))),!e&&((s=this.sample)==null?void 0:s.isSampleRead)&&this.publication.positions&&t&&(t.preventDefault(),t.stopPropagation())}handleClickThrough(t){this.mDropdowns&&this.mDropdowns.forEach(e=>{e.close()})}handleInternalLink(t){let e=t.target,r={progression:0},n=e;if(n.href.indexOf("#")!==-1){let a=n.href.slice(n.href.indexOf("#")+1);a!==null&&(r={fragment:a})}let i={href:n.href,locations:r,type:n.type,title:n.title};t.preventDefault(),t.stopPropagation(),this.stopReadAloud(!0),this.navigate(i)}handleNumberOfIframes(){if(this.publication.isFixedLayout){if(this.settings.columnCount!==1){if(this.iframes.length===1){var t=document.createElement("iframe");t.setAttribute("SCROLLING","no"),t.setAttribute("allowtransparency","true"),t.style.opacity="1",t.style.border="none",t.style.overflow="hidden",this.iframes.push(t)}let e=document.createElement("div");this.spreads.appendChild(e),e.appendChild(this.iframes[1]),this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 100% 120%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc",e.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, 0% 120%)",e.style.boxShadow="0 0 8px 2px #ccc"}else this.iframes.length===2&&(this.iframes.pop(),this.spreads.removeChild(this.spreads.lastChild)),this.firstSpread.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, -20% 120%)",this.firstSpread.style.boxShadow="0 0 8px 2px #ccc";this.precessContentForIframe()}}handleResize(){if(this.isScrolling)return;let t=this.view.getCurrentPosition();if(this.publication.isFixedLayout){var e=this.publication.getSpineIndex(this.currentChapterLink.href);let l=_u()-40-this.attributes.margin;var r=e===0&&this.iframes.length===2?this.iframes[1].parentElement.parentElement:this.iframes[0].parentElement.parentElement;r.style.height=l+40+"px";let f=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).height,c=getComputedStyle(e===0&&this.iframes.length===2?this.iframes[1].contentDocument.body:this.iframes[0].contentDocument.body).width,g=dr(e===0&&this.iframes.length===2?this.iframes[1].contentDocument:this.iframes[0].contentDocument,"head");if(g){let m=Le(g,"meta[name=viewport]");if(m){var n=m.content,i=n.split(",").reduce((p,A)=>{var[h,b]=A.match(/[^\s;=]+/g);return p[h]=isNaN(Number(b))?b:+b,p},{});(parseInt(i.height)!==0||parseInt(i.width)!==0)&&(f=i.height+"px",c=i.width+"px")}}var a=(parseInt(getComputedStyle(r).width)-100)/(this.iframes.length===2?parseInt(c.replace("px",""))*2+200:parseInt(c.replace("px",""))),o=(parseInt(getComputedStyle(r).height)-100)/parseInt(f.replace("px","")),s=Math.min(a,o);r.style.transform="scale("+s+")";for(let m of this.iframes)m.style.height=f,m.style.width=c,m.parentElement.style.height=f}this.settings.applyProperties(),this.infoTop&&(this.infoTop.style.height=0+"px"),this.infoTop&&(this.infoTop.style.minHeight=0+"px"),this.infoBottom&&(this.infoBottom.style.height=this.attributes.bottomInfoHeight?this.attributes.bottomInfoHeight+"px":40+"px"),this.view.layout!=="fixed"&&this.settings.isPaginated().then(l=>{l?(this.view.height=_u()-40-this.attributes.margin,this.infoBottom&&this.infoBottom.style.removeProperty("display")):this.infoBottom&&(this.infoBottom.style.display="none")}),setTimeout(()=>{var l;if(this.view.layout!=="fixed"&&((l=this.view)==null?void 0:l.isScrollMode()))for(let f of this.iframes)this.view.setIframeHeight(f)},100),setTimeout(()=>le(this,null,function*(){var l,f;this.view.goToPosition(t),yield this.updatePositionInfo(!1),this.annotationModule!==void 0?this.annotationModule.handleResize():((l=this.rights)==null?void 0:l.enableSearch)&&(yield this.searchModule.handleResize()),((f=this.rights)==null?void 0:f.enableContentProtection)&&this.contentProtectionModule!==void 0&&this.contentProtectionModule.handleResize()}),150)}updatePositionInfo(t=!0){return le(this,null,function*(){var e;if(this.view.layout==="fixed")this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");else if((e=this.view)==null?void 0:e.isPaginated()){let r=this.currentLocator(),n=r.displayInfo.resourceScreenIndex,i=r.displayInfo.resourceScreenCount,a=r.locations.remainingPositions;this.chapterPosition&&(a?this.chapterPosition.innerHTML="Page "+n+" of "+i:this.chapterPosition.innerHTML=""),this.remainingPositions&&(a?this.remainingPositions.innerHTML=a+" left in chapter":this.remainingPositions.innerHTML="Page "+n+" of "+i)}else this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");t&&(yield this.savePosition())})}handlePreviousChapterClick(t){if(this.view.layout==="fixed"&&this.settings.columnCount!==1){let e=this.publication.getSpineIndex(this.currentChapterLink.href);e=e-2,e<0&&(e=0);let r=this.publication.readingOrder[e],n={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(!0),this.navigate(n)}else if(this.previousChapterLink){let e={href:this.publication.getAbsoluteHref(this.previousChapterLink.href),locations:{progression:1},type:this.previousChapterLink.type,title:this.previousChapterLink.title};this.stopReadAloud(!0),this.navigate(e)}t&&(t.preventDefault(),t.stopPropagation())}handleNextChapterClick(t){if(this.view.layout==="fixed"&&this.settings.columnCount!==1){let e=this.publication.getSpineIndex(this.currentChapterLink.href);e=e+2,e>=this.publication.readingOrder.length-1&&(e=this.publication.readingOrder.length-1);let r=this.publication.readingOrder[e],n={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(!0),this.navigate(n)}else if(this.nextChapterLink){let e={href:this.publication.getAbsoluteHref(this.nextChapterLink.href),locations:{progression:0},type:this.nextChapterLink.type,title:this.nextChapterLink.title};this.stopReadAloud(!0),this.navigate(e)}t&&(t.preventDefault(),t.stopPropagation())}hideBookmarksOnEscape(t){let e=27;Er.isDisplayed(this.bookmarksView)&&t.keyCode===e&&this.hideModal(this.bookmarksView,this.bookmarksControl)}hideView(t,e){var r;this.view.layout!=="fixed"&&((r=this.view)==null?void 0:r.isScrollMode())&&(document.body.style.overflow="auto")}setActiveTOCItem(t){if(this.tocView){let e=Array.prototype.slice.call(this.tocView.querySelectorAll("li > a"));for(let n of e)n.className=n.className.replace(" active","");let r=this.tocView.querySelector('li > a[href^="'+t+'"]');r&&(r.className+=" active")}}navigate(t){return le(this,null,function*(){var n,i,a,o,s,l;if(this.publication.getTOCItem(t.href)){var r=!1;if(t.href.indexOf("#")!==-1){let f=t.href.slice(0,t.href.indexOf("#"));f===this.currentChapterLink.href&&(r=!0),this.currentChapterLink.href=f,this.currentChapterLink.type=t.type,this.currentChapterLink.title=t.title}else t.href===this.currentChapterLink.href&&(r=!0),this.currentChapterLink.href=t.href,this.currentChapterLink.type=t.type,this.currentChapterLink.title=t.title;if(this.currentSpreadLinks.left!==void 0&&this.currentSpreadLinks.right!==void 0&&(t.href===this.currentSpreadLinks.left.href||t.href===this.currentSpreadLinks.right.href))return;if(r){if(t.href.indexOf("#")!==-1){let A=t.href.slice(t.href.indexOf("#")+1);t.locations={fragment:A}}if(this.newPosition=t,this.currentTOCRawLink=t.href,t.locations.fragment===void 0?this.currentTocUrl=null:(this.newElementId=t.locations.fragment,this.currentTocUrl=this.currentChapterLink.href+"#"+this.newElementId),this.newElementId){for(let A of this.iframes){let h=A.contentDocument.getElementById(this.newElementId);this.view.goToElement(h)}this.newElementId=null}else t.highlight?this.view.goToCssSelector(t.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector):this.view.goToPosition(t.locations.progression);let f=this.currentChapterLink.href,c=this.publication.getPreviousSpineItem(f);c&&c.Href&&(this.previousChapterLink={href:c.Href,type:c.TypeLink,title:c.Title}),this.previousChapterAnchorElement&&(this.previousChapterLink?(this.previousChapterAnchorElement.href=this.publication.getAbsoluteHref(this.previousChapterLink.href),this.previousChapterAnchorElement.className=this.previousChapterAnchorElement.className.replace(" disabled","")):(this.previousChapterAnchorElement.removeAttribute("href"),this.previousChapterAnchorElement.className+=" disabled"));let g=this.publication.getNextSpineItem(f);g?this.nextChapterLink={href:g.Href,type:g.TypeLink,title:g.Title}:this.nextChapterLink=void 0,this.nextChapterAnchorElement&&(this.nextChapterLink?(this.nextChapterAnchorElement.href=this.publication.getAbsoluteHref(this.nextChapterLink.href),this.nextChapterAnchorElement.className=this.nextChapterAnchorElement.className.replace(" disabled","")):(this.nextChapterAnchorElement.removeAttribute("href"),this.nextChapterAnchorElement.className+=" disabled")),this.currentTocUrl!==null?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(f),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let m=this.publication.getSpineItem(f);m!==null&&(this.currentChapterLink.title=m.Title,this.currentChapterLink.type=m.TypeLink);let p=this.publication.getTOCItem(f);this.currentTocUrl!==null&&(p=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&p!==null&&p.Title&&(this.currentChapterLink.title=p.Title),!this.currentChapterLink.type&&p!==null&&p.TypeLink&&(this.currentChapterLink.title=p.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),yield this.updatePositionInfo()}else{if(this.searchModule!==void 0&&this.searchModule.clearSearch(),t.locations.fragment===void 0?this.currentTocUrl=null:(this.newElementId=t.locations.fragment,this.currentTocUrl=this.currentChapterLink.href+"#"+this.newElementId),this.hideIframeContents(),this.showLoadingMessageAfterDelay(),t.locations===void 0&&(t.locations={progression:0}),this.newPosition=t,this.currentTOCRawLink=t.href,this.precessContentForIframe(),((n=this.rights)==null?void 0:n.enableContentProtection)&&this.contentProtectionModule!==void 0&&(yield this.contentProtectionModule.initializeResource()),((i=this.rights)==null?void 0:i.enableMediaOverlays)&&this.mediaOverlayModule!==void 0&&(yield this.mediaOverlayModule.initializeResource(this.currentLink())),((a=this.rights)==null?void 0:a.enableContentProtection)&&this.contentProtectionModule!==void 0&&this.contentProtectionModule.recalculate(300),this.annotationModule!==void 0)yield this.annotationModule.drawHighlights(),yield this.annotationModule.showHighlights();else if(((o=this.rights)==null?void 0:o.enableSearch)&&this.searchModule!==void 0&&this.highlighter!==void 0){for(let f of this.iframes)yield this.highlighter.destroyAllhighlights(f.contentDocument);this.searchModule.drawSearch()}this.view.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),((s=this.api)==null?void 0:s.resourceFitsScreen)&&((l=this.api)==null||l.resourceFitsScreen())):this.settings.isPaginated().then(f=>{f||(this.view.atStart()&&this.view.atEnd()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):this.view.atEnd()?(this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="unset")):this.view.atStart()?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="unset")):(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none")))})}}else{let f=this.publication.getStartLink(),c=null;if(f&&f.Href&&(c=this.publication.getAbsoluteHref(f.Href)),c){let g={href:c,locations:{progression:0},created:new Date,title:f.Title};yield this.navigate(g)}}})}showIframeContents(){this.isBeingStyled=!1,setTimeout(()=>{this.isBeingStyled||this.iframes.forEach(t=>{t.style.opacity="1",t.style.border="none",t.style.overflow="hidden"})},150)}showLoadingMessageAfterDelay(){this.isLoading=!0,this.isLoading&&this.loadingMessage&&(this.loadingMessage.style.display="block",this.loadingMessage.classList.add("is-loading"))}hideIframeContents(){this.isBeingStyled=!0,this.iframes.forEach(t=>{t.style.opacity="0",t.style.border="none",t.style.overflow="hidden"})}hideLoadingMessage(){setTimeout(()=>{var t,e,r,n,i,a,o,s;this.isLoading=!1,this.loadingMessage&&(this.loadingMessage.style.display="none",this.loadingMessage.classList.remove("is-loading")),this.view.layout!=="fixed"&&(this.view.atStart()&&this.view.atEnd()?((t=this.api)==null?void 0:t.resourceFitsScreen)&&((e=this.api)==null||e.resourceFitsScreen()):this.view.atEnd()?((r=this.api)==null?void 0:r.resourceAtEnd)&&((n=this.api)==null||n.resourceAtEnd()):this.view.atStart()&&((i=this.api)==null?void 0:i.resourceAtStart)&&((a=this.api)==null||a.resourceAtStart())),((o=this.api)==null?void 0:o.resourceReady)&&((s=this.api)==null||s.resourceReady())},150)}saveCurrentReadingPosition(){return le(this,null,function*(){var e,r,n,i,a,o;if(this.annotator){var t=this.publication.getTOCItem(this.currentChapterLink.href);this.currentTocUrl!==null&&(t=this.publication.getTOCItem(this.currentTocUrl)),t===null&&(t=this.publication.getTOCItemAbsolute(this.currentChapterLink.href));let s={progression:this.view.getCurrentPosition()};if(t.Href.indexOf("#")!==-1){let f=t.Href.slice(t.Href.indexOf("#")+1);f!==null&&(s={progression:this.view.getCurrentPosition(),fragment:f})}let l;if(((r=(e=this.rights)==null?void 0:e.autoGeneratePositions)!=null?r:!1)&&this.publication.positions||this.publication.positions){let f=this.publication.positionsByHref(this.publication.getRelativeHref(t.Href)),c=Math.ceil(s.progression*(f.length-1)),g=f[c];g.locations.fragment=s.fragment,l=fn(st({},g),{href:t.Href,created:new Date,title:this.currentChapterLink.title})}else l={href:t.Href,locations:s,created:new Date,type:this.currentChapterLink.type,title:this.currentChapterLink.title};if(((n=this.sample)==null?void 0:n.isSampleRead)&&this.publication.positions&&((i=this.sampleReadEventHandler)==null||i.enforceSampleRead(l)),(a=this.api)==null?void 0:a.updateCurrentLocation)(o=this.api)==null||o.updateCurrentLocation(l).then(f=>le(this,null,function*(){return _e&&console.log("api updated current location",l),this.annotator.saveLastReadingPosition(l)}));else return _e&&console.log("save last reading position",l),this.annotator.saveLastReadingPosition(l)}else return new Promise(s=>s())})}static createBase(t){let e=document.createElement("base");return e.target="_self",e.href=t,e}static createCssLink(t){let e=document.createElement("link");return e.rel="stylesheet",e.type="text/css",e.href=t,e}static createJavascriptLink(t,e){let r=document.createElement("script");return r.type="text/javascript",r.src=t,r.async=e,r}};me();var yt=class{constructor(t){this.store=t.store}getLastReadingPosition(){return le(this,null,function*(){let t=yield this.store.get(yt.LAST_READING_POSITION);if(t){let e=JSON.parse(t);return new Promise(r=>r(e))}return new Promise(e=>e())})}initLastReadingPosition(t){return le(this,null,function*(){if(typeof t=="string")yield this.store.set(yt.LAST_READING_POSITION,t);else{let e=JSON.stringify(t);yield this.store.set(yt.LAST_READING_POSITION,e)}return new Promise(e=>e())})}saveLastReadingPosition(t){return le(this,null,function*(){if(typeof t=="string")yield this.store.set(yt.LAST_READING_POSITION,t);else{let e=JSON.stringify(t);yield this.store.set(yt.LAST_READING_POSITION,e)}return new Promise(e=>e())})}initBookmarks(t){return le(this,null,function*(){if(typeof t=="string"){let e=JSON.parse(t);return yield this.store.set(yt.BOOKMARKS,JSON.stringify(e)),new Promise(r=>r(t))}else return yield this.store.set(yt.BOOKMARKS,JSON.stringify(t)),new Promise(e=>e(t))})}saveBookmark(t){return le(this,null,function*(){let e=yield this.store.get(yt.BOOKMARKS);if(e){let r=JSON.parse(e);r.push(t),yield this.store.set(yt.BOOKMARKS,JSON.stringify(r))}else{let r=[];r.push(t),yield this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return new Promise(r=>r(t))})}locatorExists(t,e){return le(this,null,function*(){let r;switch(e){case ei.Bookmark:r=yt.BOOKMARKS;break}let n=yield this.store.get(r);return n&&JSON.parse(n).filter(o=>o.href===t.href&&o.locations.progression===t.locations.progression).length>0?new Promise(o=>o(t)):new Promise(i=>i())})}deleteBookmark(t){return le(this,null,function*(){let e=yield this.store.get(yt.BOOKMARKS);if(e){let r=JSON.parse(e);r=r.filter(n=>n.id!==t.id),yield this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return new Promise(r=>r(t))})}getBookmarks(t){return le(this,null,function*(){let e=yield this.store.get(yt.BOOKMARKS);if(e){let r=JSON.parse(e);if(t){let n=r.filter(i=>i.href===t);return n=n.sort((i,a)=>i.locations.progression-a.locations.progression),new Promise(i=>i(n))}return r=r.sort((n,i)=>n.locations.progression-i.locations.progression),new Promise(n=>n(r))}return new Promise(r=>r())})}initAnnotations(t){return le(this,null,function*(){let e;typeof t=="string"?e=JSON.parse(t):e=t;let r=[];return e.forEach(n=>{let i=`${n.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector}${n.highlight.selectionInfo.rangeInfo.startContainerChildTextNodeIndex}${n.highlight.selectionInfo.rangeInfo.startOffset}${n.highlight.selectionInfo.rangeInfo.endContainerElementCssSelector}${n.highlight.selectionInfo.rangeInfo.endContainerChildTextNodeIndex}${n.highlight.selectionInfo.rangeInfo.endOffset}`,a=Su.hash(i);n.highlight.id="R2_HIGHLIGHT_"+a;var o;o=n.color,Dr.isHexColor(o)&&(o=Dr.hexToRgbString(o)),n.highlight.color=o,n.highlight.pointerInteraction=!0,n.highlight.selectionInfo.cleanText=n.highlight.selectionInfo.rawText.trim().replace(/\n/g," ").replace(/\s\s+/g," "),r.push(n)}),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r)),new Promise(n=>n(r))})}saveAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let r=JSON.parse(e);r.push(t),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}else{let r=[];r.push(t),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return new Promise(r=>r(t))})}deleteAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let r=JSON.parse(e);r=r.filter(n=>n.id!==t),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return new Promise(r=>r(t))})}deleteSelectedAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let r=JSON.parse(e);r=r.filter(n=>n.highlight.id!==t.highlight.id),yield this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return new Promise(r=>r(t))})}getAnnotations(){return le(this,null,function*(){let t=yield this.store.get(yt.ANNOTATIONS);if(t){let e=JSON.parse(t);return e=e.sort((r,n)=>r.locations.progression-n.locations.progression),new Promise(r=>r(e))}return new Promise(e=>e())})}getAnnotationPosition(t,e){return le(this,null,function*(){let r=yield this.store.get(yt.ANNOTATIONS);if(r){let a=JSON.parse(r).filter(o=>o.id===t);if(a.length>0){let o=e.document.getElementById(`${a[0].highlight.id}`);if(o){var n=parseInt((o.hasChildNodes?o.childNodes[0]:o).style.top.replace("px",""));return new Promise(s=>s(n))}}}return new Promise(i=>i())})}getAnnotation(t){return le(this,null,function*(){let e=yield this.store.get(yt.ANNOTATIONS);if(e){let n=JSON.parse(e).filter(i=>i.highlight.id===t.id);if(n.length>0)return new Promise(i=>i(n[0]))}return new Promise(r=>r())})}},bh=yt;bh.LAST_READING_POSITION="last-reading-position";bh.BOOKMARKS="bookmarks";bh.ANNOTATIONS="annotations";me();me();var xF=class{constructor(){this.store={}}get(t){let e=this.store[t]||null;return new Promise(r=>r(e))}set(t,e){return this.store[t]=e,new Promise(r=>r())}remove(t){return this.store[t]=null,new Promise(e=>e())}},Q3=class{constructor(t){this.prefix=t.prefix,this.useLocalStorage=t.useLocalStorage;try{let e=t.prefix+"-"+String(Math.random());this.useLocalStorage?(window.localStorage.setItem(e,"test"),window.localStorage.removeItem(e)):(window.sessionStorage.setItem(e,"test"),window.sessionStorage.removeItem(e)),this.fallbackStore=null}catch(e){this.fallbackStore=new xF}}getLocalStorageKey(t){return this.prefix+"-"+t}get(t){return le(this,null,function*(){let e=null;return this.fallbackStore?e=yield this.fallbackStore.get(t):this.useLocalStorage?e=window.localStorage.getItem(this.getLocalStorageKey(t)):e=window.sessionStorage.getItem(this.getLocalStorageKey(t)),new Promise(r=>r(e))})}set(t,e){return le(this,null,function*(){return this.fallbackStore?yield this.fallbackStore.set(t,e):this.useLocalStorage?window.localStorage.setItem(this.getLocalStorageKey(t),e):window.sessionStorage.setItem(this.getLocalStorageKey(t),e),new Promise(r=>r())})}remove(t){return le(this,null,function*(){return this.fallbackStore?yield this.fallbackStore.remove(t):this.useLocalStorage?window.localStorage.removeItem(this.getLocalStorageKey(t)):window.sessionStorage.removeItem(this.getLocalStorageKey(t)),new Promise(e=>e())})}};me();var PF=It($f()),TF=It(Gr()),K3=class extends PF.Link{};K3=Rx([(0,TF.JsonObject)()],K3);function wh(t){let e,r,n,i;if(t instanceof Array)return t.map(function(a){return typeof a=="object"&&(a=wh(a)),a});e={};for(r in t)t.hasOwnProperty(r)&&(n=(r.charAt(0).toLowerCase()+r.slice(1)||r).toString(),i=t[r],(i instanceof Array||i!==null&&i.constructor===Object)&&(i=wh(i)),n==="href1"?e.href=i:n==="typeLink"?e.type=i:e[n]=i);return e}var p0=class{constructor(t,e,r,n,i,a,o,s,l,f,c,g){this.settings=t,this.ttsSettings=e,this.navigator=r,this.highlighter=n,this.bookmarkModule=i,this.annotationModule=a,this.ttsModule=o,this.searchModule=s,this.contentProtectionModule=l,this.timelineModule=f,this.mediaOverlaySettings=c,this.mediaOverlayModule=g,this.startReadAloud=()=>this.navigator.startReadAloud(),this.stopReadAloud=()=>this.navigator.stopReadAloud(),this.pauseReadAloud=()=>this.navigator.pauseReadAloud(),this.resumeReadAloud=()=>this.navigator.resumeReadAloud(),this.saveBookmark=()=>le(this,null,function*(){var m;if((m=this.navigator.rights)==null?void 0:m.enableBookmarks)return yield this.bookmarkModule.saveBookmark()}),this.deleteBookmark=m=>le(this,null,function*(){var p;if((p=this.navigator.rights)==null?void 0:p.enableBookmarks)return yield this.bookmarkModule.deleteBookmark(m)}),this.deleteAnnotation=m=>le(this,null,function*(){var p;return yield(p=this.annotationModule)==null?void 0:p.deleteAnnotation(m)}),this.addAnnotation=m=>le(this,null,function*(){var p;return yield(p=this.annotationModule)==null?void 0:p.addAnnotation(m)}),this.tableOfContents=()=>le(this,null,function*(){return yield wh(this.navigator.tableOfContents())}),this.readingOrder=()=>le(this,null,function*(){return yield wh(this.navigator.readingOrder())}),this.bookmarks=()=>le(this,null,function*(){var m;return((m=this.navigator.rights)==null?void 0:m.enableBookmarks)?yield this.bookmarkModule.getBookmarks():[]}),this.annotations=()=>le(this,null,function*(){var m,p;return(p=yield(m=this.annotationModule)==null?void 0:m.getAnnotations())!=null?p:[]}),this.search=(m,p)=>le(this,null,function*(){var A,h;return((A=this.navigator.rights)==null?void 0:A.enableSearch)?yield(h=this.searchModule)==null?void 0:h.search(m,p):[]}),this.goToSearchIndex=(m,p,A)=>le(this,null,function*(){var h,b;((h=this.navigator.rights)==null?void 0:h.enableSearch)&&(yield(b=this.searchModule)==null?void 0:b.goToSearchIndex(m,p,A))}),this.goToSearchID=(m,p,A)=>le(this,null,function*(){var h,b;((h=this.navigator.rights)==null?void 0:h.enableSearch)&&(yield(b=this.searchModule)==null?void 0:b.goToSearchID(m,p,A))}),this.clearSearch=()=>le(this,null,function*(){var m,p;((m=this.navigator.rights)==null?void 0:m.enableSearch)&&(yield(p=this.searchModule)==null?void 0:p.clearSearch())}),this.currentResource=()=>this.navigator.currentResource(),this.mostRecentNavigatedTocItem=()=>this.navigator.mostRecentNavigatedTocItem(),this.totalResources=()=>this.navigator.totalResources(),this.resetUserSettings=()=>le(this,null,function*(){return yield this.settings.resetUserSettings()}),this.applyUserSettings=m=>le(this,null,function*(){return yield this.settings.applyUserSettings(m)}),this.currentSettings=()=>this.settings.currentSettings,this.scroll=m=>le(this,null,function*(){return yield this.settings.scroll(m)}),this.increase=m=>le(this,null,function*(){var p,A;this.isTTSIncrementable(m)?((p=this.navigator.rights)==null?void 0:p.enableTTS)&&(yield this.ttsSettings.increase(m)):this.isMOIncrementable(m)?((A=this.navigator.rights)==null?void 0:A.enableMediaOverlays)&&(yield this.mediaOverlaySettings.increase(m)):yield this.settings.increase(m)}),this.decrease=m=>le(this,null,function*(){var p,A;this.isTTSIncrementable(m)?((p=this.navigator.rights)==null?void 0:p.enableTTS)&&(yield this.ttsSettings.decrease(m)):this.isMOIncrementable(m)?((A=this.navigator.rights)==null?void 0:A.enableMediaOverlays)&&(yield this.mediaOverlaySettings.decrease(m)):yield this.settings.decrease(m)}),this.resetTTSSettings=()=>{var m;((m=this.navigator.rights)==null?void 0:m.enableTTS)&&this.ttsSettings.resetTTSSettings()},this.applyTTSSettings=m=>{var p;((p=this.navigator.rights)==null?void 0:p.enableTTS)&&this.ttsSettings.applyTTSSettings(m)},this.applyTTSSetting=(m,p)=>{var A;((A=this.navigator.rights)==null?void 0:A.enableTTS)&&this.ttsSettings.applyTTSSetting(m,p)},this.applyPreferredVoice=m=>{var p;((p=this.navigator.rights)==null?void 0:p.enableTTS)&&this.ttsSettings.applyPreferredVoice(m)},this.resetMediaOverlaySettings=()=>le(this,null,function*(){var m;((m=this.navigator.rights)==null?void 0:m.enableMediaOverlays)&&(yield this.mediaOverlaySettings.resetMediaOverlaySettings())}),this.applyMediaOverlaySettings=m=>le(this,null,function*(){var p;((p=this.navigator.rights)==null?void 0:p.enableMediaOverlays)&&(yield this.mediaOverlaySettings.applyMediaOverlaySettings(m))}),this.goTo=m=>le(this,null,function*(){this.navigator.goTo(m)}),this.goToPosition=m=>le(this,null,function*(){return this.navigator.goToPosition(m)}),this.nextResource=()=>le(this,null,function*(){this.navigator.nextResource()}),this.previousResource=()=>le(this,null,function*(){this.navigator.previousResource()}),this.nextPage=()=>le(this,null,function*(){this.navigator.nextPage()}),this.previousPage=()=>le(this,null,function*(){this.navigator.previousPage()}),this.atStart=()=>le(this,null,function*(){return this.navigator.atStart()}),this.atEnd=()=>le(this,null,function*(){return this.navigator.atEnd()}),this.snapToElement=m=>le(this,null,function*(){this.navigator.snapToElement(m)}),this.applyAttributes=m=>{this.navigator.applyAttributes(m)},this.stop=()=>{var m,p,A,h,b,w,_,E,y;document.body.onscroll=()=>{},this.navigator.stop(),this.settings.stop(),(m=this.ttsSettings)==null||m.stop(),(p=this.ttsModule)==null||p.stop(),(A=this.bookmarkModule)==null||A.stop(),(h=this.annotationModule)==null||h.stop(),(b=this.searchModule)==null||b.stop(),(w=this.contentProtectionModule)==null||w.stop(),(_=this.timelineModule)==null||_.stop(),(E=this.mediaOverlaySettings)==null||E.stop(),(y=this.mediaOverlayModule)==null||y.stop()}}static build(t){return le(this,null,function*(){var x,R,z,T,P,I,H,j,S,B,L,F,D,q,V,k,K,de,oe,se,ae,ce,U,ee;((x=t.rights)==null?void 0:x.enableContentProtection)&&t.protection&&(yield J3.setupPreloadProtection(t.protection));let e=rr(document,"#D2Reader-Container"),r=Le(document,"#headerMenu"),n=Le(document,"#footerMenu"),i=t.url,a=new Q3({prefix:i.href,useLocalStorage:(R=t.useLocalStorage)!=null?R:!1}),o=new Q3({prefix:"r2d2bc-reader",useLocalStorage:(z=t.useLocalStorage)!=null?z:!1}),s=new bh({store:a}),l=(T=t.upLinkUrl)!=null?T:void 0,f=yield ih.fromUrl(i),c=RF(t,f);f.sample=c.sample,((I=(P=c.rights)==null?void 0:P.autoGeneratePositions)!=null?I:!0)?yield f.autoGeneratePositions():(((H=c.services)==null?void 0:H.positions)&&(yield f.fetchPositionsFromService((j=c.services)==null?void 0:j.positions.href)),((S=c.services)==null?void 0:S.weight)&&(yield f.fetchWeightsFromService((B=c.services)==null?void 0:B.weight.href)));let g=yield Ou.create({store:o,initialUserSettings:c.userSettings,headerMenu:r,material:c.material,api:c.api,injectables:((F=(L=f.Metadata.Rendition)==null?void 0:L.Layout)!=null?F:"unknown")==="fixed"?c.injectablesFixed:c.injectables,layout:((q=(D=f.Metadata.Rendition)==null?void 0:D.Layout)!=null?q:"unknown")==="fixed"?"fixed":"reflowable"}),m=yield Er.create({mainElement:e,headerMenu:r,footerMenu:n,publication:f,settings:g,annotator:s,upLink:l,initialLastReadingPosition:c.lastReadingPosition,material:c.material,api:c.api,rights:c.rights,tts:c.tts,sample:c.sample,injectables:((k=(V=f.Metadata.Rendition)==null?void 0:V.Layout)!=null?k:"unknown")==="fixed"?c.injectablesFixed:c.injectables,attributes:c.attributes,services:c.services}),A=f.isReflowable?yield Dr.create(st({delegate:m},c.highlighter)):void 0,h=((K=c.rights)==null?void 0:K.enableBookmarks)?yield G3.create(st({annotator:s,headerMenu:r,rights:c.rights,publication:f,delegate:m,initialAnnotations:c.initialAnnotations},c.bookmarks)):void 0,b=((de=c.rights)==null?void 0:de.enableAnnotations)?yield W3.create(st({annotator:s,headerMenu:r,rights:c.rights,publication:f,delegate:m,initialAnnotations:c.initialAnnotations,highlighter:A},c.annotations)):void 0,w=(oe=c.rights)==null?void 0:oe.enableTTS,_=w?yield yF.create(st({store:o,initialTTSSettings:c.tts,headerMenu:r},c.tts)):void 0,E=w?yield vF.create(st({delegate:m,tts:_,headerMenu:r,rights:c.rights,highlighter:A},c.tts)):void 0,y=((se=c.rights)==null?void 0:se.enableSearch)?yield AF.create(st({headerMenu:r,delegate:m,publication:f,highlighter:A},c.search)):void 0,u=((ae=c.rights)==null?void 0:ae.enableTimeline)?yield oF.create({publication:f,delegate:m}):void 0,d=((ce=c.rights)==null?void 0:ce.enableContentProtection)?yield J3.create(st({delegate:m},c.protection)):void 0,v=(ee=(U=c.rights)==null?void 0:U.enableMediaOverlays)!=null?ee:!1,C=v?yield iF.create(st({store:o,initialMediaOverlaySettings:c.mediaOverlays,headerMenu:r},c.mediaOverlays)):void 0,O=v?yield aF.create(st({publication:f,settings:C,delegate:m},c.mediaOverlays)):void 0;return new p0(g,_,m,A,h,b,E,y,d,u,C,O)})}get publicationLanguage(){return this.navigator.publication.Metadata.Language}isTTSIncrementable(t){return t==="pitch"||t==="rate"||t==="volume"}isMOIncrementable(t){return t==="mo_volume"}get currentLocator(){return this.navigator.currentLocator()}get positions(){return this.navigator.positions()}};function RF(t,e){return e.isFixedLayout&&(t.rights||(t.rights={}),t.rights.enableAnnotations=!1,t.rights.enableSearch=!1,t.rights.enableTTS=!1),t}var $3=p0,pye=p0.build;var en=Ce(require("react"));var Eh=window.location.origin,MF=[{type:"style",url:`${Eh}/css/ReadiumCSS-before.css`,r2before:!0},{type:"style",url:`${Eh}/css/ReadiumCSS-default.css`,r2default:!0},{type:"style",url:`${Eh}/css/ReadiumCSS-after.css`,r2after:!0},{type:"style",url:`${Eh}/fonts/opendyslexic/opendyslexic.css`,fontFamily:"opendyslexic"}],eP=MF;function kF(t,e){var r;switch(e.type){case"SET_READER":{let n=e.reader.currentSettings();return{reader:e.reader,isScrolling:n.verticalScroll,colorMode:DF(n.appearance),fontSize:n.fontSize,fontFamily:(r=LF[n.fontFamily])!=null?r:"publisher",currentTocUrl:e.reader.mostRecentNavigatedTocItem()}}case"SET_COLOR_MODE":return ut(Ze({},t),{colorMode:e.mode});case"SET_SCROLL":return ut(Ze({},t),{isScrolling:e.isScrolling});case"SET_FONT_SIZE":return ut(Ze({},t),{fontSize:e.size});case"SET_FONT_FAMILY":return ut(Ze({},t),{fontFamily:e.family});case"SET_CURRENT_TOC_URL":return ut(Ze({},t),{currentTocUrl:e.currentTocUrl})}}var tP=4;function m0(t){let{webpubManifestUrl:e,manifest:r,getContent:n}=t!=null?t:{},[i,a]=en.default.useReducer(kF,{colorMode:"day",isScrolling:!1,fontSize:16,fontFamily:"sans-serif",reader:void 0,currentTocUrl:null}),{reader:o,fontSize:s}=i;en.default.useEffect(()=>{if(!e)return;let w=new URL(e);$3.build({url:w,injectables:eP,injectablesFixed:[],attributes:{navHeight:ea,margin:0},rights:{autoGeneratePositions:!1},api:{getContent:n}}).then(_=>{a({type:"SET_READER",reader:_})})},[e,n]);let l=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=yield o.atEnd();o.nextPage(),w&&a({type:"SET_CURRENT_TOC_URL",currentTocUrl:o.mostRecentNavigatedTocItem()})}),[o]),f=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=yield o.atStart();o.previousPage(),w&&a({type:"SET_CURRENT_TOC_URL",currentTocUrl:o.mostRecentNavigatedTocItem()})}),[o]),c=en.default.useCallback(w=>le(this,null,function*(){!o||(a({type:"SET_COLOR_MODE",mode:w}),yield o.applyUserSettings({appearance:w}))}),[o]),g=en.default.useCallback(w=>le(this,null,function*(){let _=w==="scrolling";yield o==null?void 0:o.scroll(_),a({type:"SET_SCROLL",isScrolling:_})}),[o]),m=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=s+tP;yield o.applyUserSettings({fontSize:w}),a({type:"SET_FONT_SIZE",size:w})}),[o,s]),p=en.default.useCallback(()=>le(this,null,function*(){if(!o)return;let w=s-tP;yield o.applyUserSettings({fontSize:w}),a({type:"SET_FONT_SIZE",size:w})}),[o,s]),A=en.default.useCallback(w=>le(this,null,function*(){if(!o)return;let _=BF[w];yield o.applyUserSettings({fontFamily:_}),a({type:"SET_FONT_FAMILY",family:w})}),[o]),h=en.default.useCallback(w=>{if(!!o)try{o.goTo({href:w}),a({type:"SET_CURRENT_TOC_URL",currentTocUrl:w})}catch(_){console.error(_)}},[o]),b=!o;return!e||!r?null:b?{type:null,isLoading:!0,content:en.default.createElement(iu,null),navigator:null,manifest:null,state:null}:{type:"HTML",isLoading:!1,content:en.default.createElement(iu,null),state:i,manifest:r,navigator:{goForward:l,goBackward:f,setColorMode:c,setScroll:g,increaseFontSize:m,decreaseFontSize:p,setFontFamily:A,goToPage:h}}}function DF(t){switch(t){case"readium-default-on":return"day";case"readium-night-on":return"night";case"readium-sepia-on":return"sepia";default:return console.error("COLOR MODE SLIPPED THROUG",t),"day"}}var BF={publisher:"Original",serif:"serif","sans-serif":"sans-serif","open-dyslexic":"opendyslexic"},LF={Original:"publisher",serif:"serif","sans-serif":"sans-serif",opendyslexic:"open-dyslexic"};var rP="https://librarysimplified.org/terms/profiles/pdf",nP="stub/webpub+axisnow";function jF(t){switch(t){case nP:return"HTML";case rP:return"PDF";case void 0:return"HTML";case null:return}}function A0(t){let{webpubManifestUrl:e,getContent:r,proxyUrl:n}=t,[i,a]=Ch.default.useState(null),o=jF(i?i.metadata.conformsTo:null),s=m0(o==="HTML"&&i?{webpubManifestUrl:e,manifest:i,getContent:r}:void 0),l=Tg(o==="PDF"&&i?{webpubManifestUrl:e,manifest:i,proxyUrl:n}:void 0);if(Ch.default.useEffect(()=>{kS(e).then(a)},[e]),i===null)return{isLoading:!0,content:Ch.default.createElement(iu,null),manifest:null,navigator:null,state:null,type:null};if(s)return s;if(l)return l;throw new Error(`No reader was initialized for the webpub with url: ${e} and type: ${o}.`)}var IF=({webpubManifestUrl:t,proxyUrl:e,getContent:r})=>{let n=A0({webpubManifestUrl:t,proxyUrl:e,getContent:r}),{content:i}=n;return iP.default.createElement(MS,Ze({},n),i)},NF=IF;
607
607
  /*!
608
608
  * Materialize v1.0.0 (http://materializecss.com)
609
609
  * Copyright 2014-2017 Materialize