@d-i-t-a/reader 2.1.2 → 2.1.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/esm/index.js +8 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/reader.js +1 -1
- package/dist/reader.js.map +2 -2
- package/dist/types/modules/pagebreak/PageBreakModule.d.ts +1 -1
- package/dist/types/navigator/IFrameNavigator.d.ts +1 -0
- package/dist/types/reader.d.ts +1 -0
- package/package.json +1 -1
package/dist/reader.js
CHANGED
|
@@ -79,7 +79,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
79
79
|
<span>There was an error loading this page.</span>
|
|
80
80
|
<button class="go-back">Go back</button>
|
|
81
81
|
<button class="try-again">Try again</button>
|
|
82
|
-
`;var zd=Je(Qi());C();var Ks=class{constructor(t){this.onBackwardSwipe=()=>{};this.onForwardSwipe=()=>{};this.setupEvents=t=>{let n=null,r=null,o=this;t&&(t.addEventListener("touchstart",function(a){a.changedTouches.length===1&&(n=a)},!1),t.addEventListener("touchend",function(a){if(a.changedTouches.length!==1||!n)return;let l=n.changedTouches[0],u=a.changedTouches[0];if(!l)return;let d=window.devicePixelRatio,f=(l.clientX-u.clientX)/d,g=(l.clientY-u.clientY)/d;if(Math.abs(f)<Ks.TAP_TOLERANCE&&Math.abs(g)<Ks.TAP_TOLERANCE){if(r){n=null,r=null;return}if(a.timeStamp-n.timeStamp>Ks.LONG_PRESS_MS){n=null,r=null;return}n=null,r=a;return}if(r=null,a.timeStamp-n.timeStamp>Ks.SLOW_SWIPE_MS){n=null;return}let y=(l.clientY-u.clientY)/(l.clientX-u.clientX);if(Math.abs(y)>.5){n=null;return}f<0?o.onBackwardSwipe(a):o.onForwardSwipe(a),n=null},!1))};this.navigator=t}},Go=Ks;Go.TAP_TOLERANCE=10,Go.LONG_PRESS_MS=500,Go.SLOW_SWIPE_MS=500;C();var $d=class{constructor(t){this.onBackwardSwipe=()=>{};this.onForwardSwipe=()=>{};this.setupEvents=t=>{t&&(this.focusin(t),this.keydown(t))};this.focusin=t=>{let n=this;t.addEventListener("focusin",function(r){n.navigator.view?.snap(r.target)},!0)};this.keydown=t=>{let n=this;this.navigator.rights.customKeyboardEvents||t.addEventListener("keydown",function(r){let o=r.target;if(/input|select|option|textarea/i.test(o.tagName)||!(o.ownerDocument||o).defaultView.getSelection().isCollapsed)return;switch(r.key){case"ArrowRight":n.onForwardSwipe(r);break;case"ArrowLeft":n.onBackwardSwipe(r);break}},!1)};this.navigator=t}};C();var A3=Je(Qi()),Ud=class{constructor(t){this.enforceSampleRead=(0,A3.debounce)(t=>{let n=Math.round(t.locations.totalProgression*100),r=!1;this.delegate.sample?.limit&&(r=n<=this.delegate.sample?.limit,this.delegate.view?.layout==="fixed"&&!r&&this.delegate.sample?.minimum&&t.locations.position<=this.delegate.sample?.minimum&&(r=!0));let o={37:1,38:0,39:1,40:1,32:1,33:1,34:1,35:1,36:1};function a(w){w.preventDefault()}function l(w){o[w.keyCode]&&!r&&a(w)}let u=!1,d=Object.defineProperty&&Object.defineProperty({},"passive",{get:function(){u=!0}});window.addEventListener("test",function(){},d);let f=u?{passive:!1}:!1;function g(w){w=w||window.event;let b=Math.max(-1,Math.min(1,w.wheelDelta||-w.detail));return b===-1&&!r&&w.preventDefault(),!1}let y;function v(w){w=w||window.event;let b=w.target||w.srcElement,m=w.touches[0].clientY;if(!(m>y)){if(m<y&&!r)return b.className.match(/\baltNav\b/)||(w.returnValue=!1,w.cancelable&&(w.cancelBubble=!0),w.preventDefault&&w.cancelable&&(w.preventDefault(),w.stopPropagation())),!1}return y=m,!1}function S(w){return w=w||window.event,y=w.touches[0].clientY,!1}window.addEventListener("mousewheel",g,f),window.addEventListener("DOMMouseScroll",g,f),window.addEventListener("keydown",l,f),window.addEventListener("touchmove",v,f),window.addEventListener("touchstart",S,f),r?(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=this.delegate.sample?.popup??""))},300);this.delegate=t}};var M3=Je(R3()),Yn=Je(Dt()),Ln=class extends M3.default{constructor(t,n=void 0,r=void 0,o,a,l,u,d,f,g,y,v){super();this.iframes=[];this.sideNavExpanded=!1;this.currentChapterLink={href:""};this.currentSpreadLinks={};this.rights={autoGeneratePositions:!1,enableAnnotations:!1,enableBookmarks:!1,enableContentProtection:!1,enableDefinitions:!1,enableLineFocus:!1,enableMediaOverlays:!1,enablePageBreaks:!1,enableSearch:!1,enableTTS:!1,enableTimeline:!1,customKeyboardEvents:!1,enableHistory:!1,enableCitations:!1};this.didInitKeyboardEventHandler=!1;this.onResize=()=>{clearTimeout(this.timeout),this.timeout=setTimeout(this.handleResize.bind(this),200)};this.reload=async()=>{let t;if(this.annotator&&(t=await this.annotator.getLastReadingPosition()),t){let n=this.publication.getAbsoluteHref(t.href);Yn.default.log(t.href),Yn.default.log(n),t.href=n,await this.navigate(t)}};this.savePosition=(0,zd.debounce)(()=>{this.annotator&&this.saveCurrentReadingPosition()},200);this.checkResourcePosition=(0,zd.debounce)(()=>{this.view?.atStart()&&this.view?.atEnd()?(this.api?.resourceFitsScreen&&this.api?.resourceFitsScreen(),this.emit("resource.fits")):this.view?.atEnd()?(this.api?.resourceAtEnd&&this.api?.resourceAtEnd(),this.emit("resource.end")):this.view?.atStart()&&(this.api?.resourceAtStart&&this.api?.resourceAtStart(),this.emit("resource.start"))},200);this.settings=t,this.annotator=n,this.view=t.view,this.view.attributes=f,this.view.delegate=this,this.eventHandler=new pd(this),this.touchEventHandler=new Go(this),this.keyboardEventHandler=new $d(this),this.initialLastReadingPosition=r,this.publication=o,this.api=a,this.rights=l??{autoGeneratePositions:!1,enableAnnotations:!1,enableBookmarks:!1,enableContentProtection:!1,enableDefinitions:!1,enableLineFocus:!1,enableMediaOverlays:!1,enablePageBreaks:!1,enableSearch:!1,enableTTS:!1,enableTimeline:!1,customKeyboardEvents:!1,enableHistory:!1,enableCitations:!1},this.tts=u,this.injectables=d,this.attributes=f||{margin:0},this.services=g,this.sample=y,this.requestConfig=v,this.sampleReadEventHandler=new Ud(this)}static async create(t){let n=new this(t.settings,t.annotator||void 0,t.initialLastReadingPosition||void 0,t.publication,t.api,t.rights,t.tts,t.injectables,t.attributes||{margin:0},t.services,t.sample,t.requestConfig);return await n.start(t.mainElement,t.headerMenu,t.footerMenu),new Promise(r=>r(n))}stop(){Yn.default.log("Iframe navigator stop"),Pe(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),Pe(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),Pe(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Pe(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),Pe(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Pe(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),Pe(this.tryAgainButton,"click",this.tryAgain.bind(this)),Pe(this.goBackButton,"click",Ln.goBack.bind(this)),Pe(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),Pe(window,"resize",this.onResize),this.iframes.forEach(t=>{Pe(t,"resize",this.onResize)})}async start(t,n,r){this.headerMenu=n,this.mainElement=t;try{let S=dt(t,"main#iframe-wrapper");S.style.overflow="auto";let w=de(t,"main#iframe-wrapper iframe"),b=de(t,"#second");if(w&&this.iframes.push(w),b&&this.iframes.push(b),window.matchMedia("screen and (max-width: 600px)").matches&&(this.settings.columnCount=1),this.iframes.length===0){S.style.overflow="auto";let m=document.createElement("iframe");if(m.setAttribute("SCROLLING","no"),m.setAttribute("allowtransparency","true"),this.iframes.push(m),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]),S.appendChild(this.spreads)):(m.setAttribute("height","100%"),m.setAttribute("width","100%"),S.appendChild(this.iframes[0])),this.publication.isFixedLayout)if(this.settings.columnCount!==1&&!window.matchMedia("screen and (max-width: 600px)").matches){let E=document.createElement("div");this.spreads.appendChild(E);let O=document.createElement("iframe");O.setAttribute("SCROLLING","no"),O.setAttribute("allowtransparency","true"),O.style.opacity="1",O.style.border="none",O.style.overflow="hidden",this.iframes.push(O),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.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=(this.attributes?.iframePaddingTop??0)+"px"}if(this.publication.isFixedLayout){let m=S.clientHeight;var o=this.iframes[0].parentElement?.parentElement;o.style.height=m+40+"px"}else this.iframes.length===2&&this.iframes.pop();if(this.loadingMessage=de(t,"#reader-loading"),this.loadingMessage&&(this.loadingMessage.innerHTML=_3,this.loadingMessage.style.display="none"),this.errorMessage=de(t,"#reader-error"),this.errorMessage&&(this.errorMessage.innerHTML=T3,this.errorMessage.style.display="none"),this.tryAgainButton=de(t,"button[class=try-again]"),this.goBackButton=de(t,"button[class=go-back]"),this.infoTop=de(t,"div[class='info top']"),this.infoBottom=de(t,"div[class='info bottom']"),this.headerMenu&&(this.bookTitle=de(this.headerMenu,"#book-title")),this.infoBottom&&(this.chapterTitle=de(this.infoBottom,"span[class=chapter-title]")),this.infoBottom&&(this.chapterPosition=de(this.infoBottom,"span[class=chapter-position]")),this.infoBottom&&(this.remainingPositions=de(this.infoBottom,"span[class=remaining-positions]")),this.headerMenu&&(this.espandMenuIcon=de(this.headerMenu,"#expand-menu")),this.headerMenu&&(this.links=de(this.headerMenu,"ul.links.top")),this.headerMenu&&(this.linksTopLeft=de(this.headerMenu,"#nav-mobile-left")),this.headerMenu&&(this.tocView=de(this.headerMenu,"#container-view-toc")),this.headerMenu&&(this.landmarksView=de(this.headerMenu,"#container-view-landmarks")),this.headerMenu&&(this.landmarksSection=de(this.headerMenu,"#sidenav-section-landmarks")),this.headerMenu&&(this.pageListView=de(this.headerMenu,"#container-view-pagelist")),r&&(this.linksBottom=de(r,"ul.links.bottom")),r&&(this.linksMiddle=de(r,"ul.links.middle")),this.headerMenu&&(this.nextChapterAnchorElement=de(this.headerMenu,"a[rel=next]")),this.headerMenu&&(this.nextChapterBottomAnchorElement=de(t,"#next-chapter")),r&&(this.nextPageAnchorElement=de(r,"a[rel=next]")),this.headerMenu&&(this.previousChapterAnchorElement=de(this.headerMenu,"a[rel=prev]")),this.headerMenu&&(this.previousChapterTopAnchorElement=de(t,"#previous-chapter")),r&&(this.previousPageAnchorElement=de(r,"a[rel=prev]")),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.newPosition=void 0,this.newElementId=void 0,this.isBeingStyled=!0,this.isLoading=!0,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),this.headerMenu){var a=de(this.headerMenu,"#menu-button-search"),l=de(this.headerMenu,"#menu-button-tts"),u=de(this.headerMenu,"#menu-button-bookmark"),d=de(this.headerMenu,"#menu-button-play"),f=de(this.headerMenu,"#menu-button-pause"),g=de(this.headerMenu,"#menu-button-mediaoverlay");if(!this.rights.enableBookmarks){u&&u.parentElement?.style.setProperty("display","none");var y=de(this.headerMenu,"#sidenav-section-bookmarks");y&&y.style.setProperty("display","none")}if(!this.rights.enableAnnotations){var v=de(this.headerMenu,"#sidenav-section-highlights");v&&v.style.setProperty("display","none")}this.rights.enableTTS||l&&l.parentElement?.style.setProperty("display","none"),this.rights.enableSearch||a&&a.parentElement?.style.setProperty("display","none"),a&&this.view?.delegate.publication.isFixedLayout&&a.parentElement?.style.setProperty("display","none"),this.hasMediaOverlays?(d&&d.parentElement?.style.removeProperty("display"),f&&f.parentElement?.style.removeProperty("display"),g&&g.parentElement?.style.removeProperty("display")):(d&&d.parentElement?.style.setProperty("display","none"),f&&f.parentElement?.style.setProperty("display","none"),g&&g.parentElement?.style.setProperty("display","none"))}else a&&a.parentElement?.style.setProperty("display","none"),l&&l.parentElement?.style.setProperty("display","none"),u&&u.parentElement?.style.setProperty("display","none");return this.setupEvents(),await this.loadManifest()}catch(S){return Yn.default.error(S),this.abortOnError(S),Promise.reject(S)}}setupEvents(){for(let t of this.iframes)ne(t,"load",this.handleIFrameLoad.bind(this));ne(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),ne(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),ne(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),ne(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),ne(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),ne(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),ne(this.tryAgainButton,"click",this.tryAgain.bind(this)),ne(this.goBackButton,"click",Ln.goBack.bind(this)),ne(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),ne(window,"resize",this.onResize);for(let t of this.iframes)ne(t,"resize",this.onResize)}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.keyboardEventHandler&&(this.keyboardEventHandler.onBackwardSwipe=this.handlePreviousChapterClick.bind(this),this.keyboardEventHandler.onForwardSwipe=this.handleNextChapterClick.bind(this)),this.touchEventHandler&&(this.touchEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.touchEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this))):(this.settings.isPaginated().then(t=>{if(t)this.view.height=Fr()-40-(this.attributes?.margin??0),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 n=(0,zd.debounce)(()=>{this.isScrolling=!1},200),r=dt(document,"#iframe-wrapper");r.onscroll=async()=>{this.isScrolling=!0,await 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(o=>{o||(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()),n()},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(async()=>{await this.highlighter?.prepareContainers(this.iframes[0].contentWindow),this.pageBreakModule!==void 0&&(await this.highlighter?.destroyHighlights(qe.PageBreak),await this.pageBreakModule.drawPageBreaks()),this.annotationModule!==void 0&&await this.annotationModule.drawHighlights(),this.bookmarkModule!==void 0&&await this.bookmarkModule.drawBookmarks(),this.rights.enableSearch&&this.searchModule!==void 0&&this.highlighter!==void 0&&(await this.highlighter.destroyHighlights(qe.Search),this.searchModule.drawSearch()),this.rights.enableDefinitions&&this.definitionsModule!==void 0&&this.highlighter!==void 0&&await this.definitionsModule.drawDefinitions()},200))}async loadManifest(){try{let t=(d,f,g=!1)=>{var y=document.createElement("ul");g&&(y=document.createElement("ol")),y.className="sidenav-toc";for(let v of f){let S=document.createElement("li"),w=document.createElement("a"),b=document.createElement("span");w.className="chapter-link",w.tabIndex=-1;let m="";v.Href?(m=this.publication.getAbsoluteHref(v.Href),w.href=m,w.innerHTML=v.Title||"",S.appendChild(w)):(b.innerHTML=v.Title||"",b.className="chapter-title",S.appendChild(b)),v.Children&&v.Children.length>0&&t(S,v.Children,!0),y.appendChild(S)}ne(y,"click",v=>{if(v.preventDefault(),v.stopPropagation(),v.target&&v.target.tagName.toLowerCase()==="a"){let S=v.target;if(S.className.indexOf("active")!==-1)this.hideView();else{let w={progression:0};if(S.href.indexOf("#")!==-1){let m=S.href.slice(S.href.indexOf("#")+1);m!==void 0&&(w={fragment:m})}let b={href:S.href,locations:w,type:S.type,title:S.title};this.hideView(),this.navigate(b)}}}),d.appendChild(y)},n=this.publication.tableOfContents,r=this.publication.landmarks,o=this.publication.pageList;this.tocView&&(n.length?t(this.tocView,n):this.tocView.parentElement?.parentElement?.removeChild(this.tocView.parentElement)),this.pageListView&&(o?.length?t(this.pageListView,o):this.pageListView.parentElement?.parentElement?.removeChild(this.pageListView.parentElement)),this.landmarksView&&(r?.length?t(this.landmarksView,r):this.landmarksSection.parentElement?.removeChild(this.landmarksSection));let a;this.annotator&&(a=await this.annotator.getLastReadingPosition());let l=this.publication.getStartLink(),u;if(l&&l.Href&&(u=this.publication.getAbsoluteHref(l.Href)),a){let d=this.publication.getAbsoluteHref(a.href);Yn.default.log(a.href),Yn.default.log(d),a.href=d,await this.navigate(a)}else if(u){let d={href:u,locations:{progression:0},created:new Date,title:l?.Title};await this.navigate(d)}return new Promise(d=>d())}catch(t){return Yn.default.error(t),this.abortOnError(t),new Promise((n,r)=>r(t)).catch(()=>{})}}async handleIFrameLoad(){this.errorMessage&&(this.errorMessage.style.display="none"),this.showLoadingMessageAfterDelay();try{let t=0;this.newPosition&&(t=this.newPosition.locations.progression),await this.handleResize(),this.updateBookView(),await this.settings.applyProperties();let n=this.currentChapterLink.href;if(n){let d=this.publication.getPreviousSpineItem(n);d&&d.Href&&(this.previousChapterLink={href:d.Href,title:d.Title,type:d.TypeLink})}this.previousChapterAnchorElement&&(this.previousChapterLink&&this.previousChapterLink.href?(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 r=this.publication.getNextSpineItem(n);r?this.nextChapterLink={href:r.Href,title:r.Title,type:r.TypeLink}:this.nextChapterLink=void 0,this.nextChapterAnchorElement&&(this.nextChapterLink&&this.nextChapterLink.href?(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.historyModule&&this.historyModule.setup(),this.currentTocUrl!==void 0?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(n),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let o=this.publication.getSpineItem(n);o!==void 0&&(this.currentChapterLink.title=o.Title,this.currentChapterLink.type=o.TypeLink);let a=this.publication.getTOCItem(n);this.currentTocUrl!==void 0&&(a=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&a!==void 0&&a.Title&&(this.currentChapterLink.title=a.Title),!this.currentChapterLink.type&&a!==void 0&&a.TypeLink&&(this.currentChapterLink.title=a.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),await this.injectInjectablesIntoIframeHead(),this.highlighter!==void 0&&await this.highlighter.initialize();let u=this.iframes[0].contentDocument?.body?.querySelector("details");if(u){let d=this;u.addEventListener("toggle",async f=>{await d.view?.setIframeHeight?.(this.iframes[0])})}if(this.rights.enableContentProtection&&this.contentProtectionModule!==void 0&&await this.contentProtectionModule.initialize(),this.eventHandler){for(let d of this.iframes)this.eventHandler.setupEvents(d.contentDocument),this.touchEventHandler.setupEvents(d.contentDocument),this.keyboardEventHandler.setupEvents(d.contentDocument);this.touchEventHandler.setupEvents(this.errorMessage),this.didInitKeyboardEventHandler||(this.keyboardEventHandler.keydown(document),this.didInitKeyboardEventHandler=!0)}if(this.view?.layout!=="fixed"&&this.view?.isScrollMode()&&(this.iframes[0].height="0",this.view?.setIframeHeight?.(this.iframes[0])),this.annotationModule!==void 0&&await this.annotationModule.initialize(),this.bookmarkModule!==void 0&&await this.bookmarkModule.initialize(),this.rights.enableTTS)for(let d of this.iframes){let f=d.contentDocument?.body;this.ttsModule!==void 0&&await this.ttsModule.initialize(f)}return this.timelineModule!==void 0&&await this.timelineModule.initialize(),this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&await this.mediaOverlayModule.initialize(),setTimeout(async()=>{if(this.newElementId){let d=this.iframes[0].contentDocument.getElementById(this.newElementId);this.view?.goToElement?.(d),this.newElementId=void 0}else if(this.newPosition&&this.newPosition.highlight){let d=this.newPosition.highlight?.selectionInfo.rangeInfo.startContainerElementCssSelector;d&&this.view?.goToCssSelector(d)}else t&&t>=0&&this.view?.goToProgression(t);if(this.newPosition=void 0,this.rights?.enableContentProtection&&this.contentProtectionModule!==void 0&&await this.contentProtectionModule.recalculate(10),this.hideLoadingMessage(),this.showIframeContents(),this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays){let d=this.currentLink();await this.mediaOverlayModule?.initializeResource(d)}await this.updatePositionInfo(),await this.view?.setSize(),setTimeout(()=>{this.mediaOverlayModule!==void 0&&(this.mediaOverlayModule.settings.resourceReady=!0)},300)},200),new Promise(d=>d())}catch(t){return Yn.default.error(t),this.abortOnError(t),Promise.reject(t)}}async injectInjectablesIntoIframeHead(){let t=[],n=r=>{let o=new Promise((a,l)=>{r.onload=()=>{a(!0)},r.onerror=u=>{let d=typeof u=="string"?u:`Injectable failed to load at: ${"href"in r?r.href:r.src}`;l(new Error(d))}});t.push(o)};for(let r of this.iframes){let o=r.contentDocument?.head;o&&(r.contentDocument.getElementsByTagName("base").length===0&&o.insertBefore(Ln.createBase(this.currentChapterLink.href),o.firstChild),this.injectables?.forEach(l=>{if(l.type==="style"){if(l.fontFamily){if(this.settings.initAddedFont(),!l.systemFont&&l.url){let u=Ln.createCssLink(l.url);o.appendChild(u),n(u)}}else if(l.r2before&&l.url){let u=Ln.createCssLink(l.url);o.insertBefore(u,o.firstChild),n(u)}else if(l.r2default&&l.url){let u=Ln.createCssLink(l.url);o.insertBefore(u,o.childNodes[1]),n(u)}else if(l.r2after&&l.url){l.appearance&&this.settings.initAddedAppearance();let u=Ln.createCssLink(l.url);o.appendChild(u),n(u)}else if(l.url){let u=Ln.createCssLink(l.url);o.appendChild(u),n(u)}}else if(l.type==="script"&&l.url){let u=Ln.createJavascriptLink(l.url,l.async??!1);o.appendChild(u),n(u)}}))}t.length!==0&&await Promise.all(t)}abortOnError(t){if(this.api?.onError){let n=t instanceof Error?t:typeof t=="string"?new Error(t):new Error("An unknown error occurred in the IFrameNavigator.");this.api.onError(n)}else this.errorMessage&&(this.errorMessage.style.display="block"),this.isLoading&&this.hideLoadingMessage()}tryAgain(){this.precessContentForIframe()}precessContentForIframe(){let t=this;var n=this.publication.getSpineIndex(this.currentChapterLink.href),r=(n??0)%2==1;this.showLoadingMessageAfterDelay();function o(d,f){let y=new DOMParser().parseFromString(d,"application/xhtml+xml");y.head&&y.getElementsByTagName("base").length===0&&y.head.insertBefore(Ln.createBase(f),y.head.firstChild);let v=y.documentElement.outerHTML,S=t.iframes[0].contentDocument;S&&(S.open(),S.write(v),S.close())}function a(d,f){let y=new DOMParser().parseFromString(d,"application/xhtml+xml");y.head&&y.getElementsByTagName("base").length===0&&y.head.insertBefore(Ln.createBase(f),y.head.firstChild);let v=y.documentElement.outerHTML,S=t.iframes[1].contentDocument;S&&(S.open(),S.write(v),S.close())}let l=new URL(this.currentChapterLink.href),u=window.location.protocol===l.protocol&&window.location.port===l.port&&window.location.hostname===l.hostname;if(this.api?.getContent)if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.api?.getContent(this.currentChapterLink.href).then(d=>{d===void 0?u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{o.call(this,f,this.currentChapterLink.href)}):o.call(this,d,this.currentChapterLink.href)}),this.iframes.length===2)if((n??0)<this.publication.readingOrder.length-1){let d=this.publication.getNextSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.right={href:f},this.api?.getContent(f).then(g=>{g===void 0?u?this.iframes[1].src=f:fetch(f,this.requestConfig).then(y=>y.text()).then(async y=>{a.call(this,y,f),this.currentSpreadLinks.right={href:f}}):a.call(this,g,f)})}}else this.iframes[1].src="about:blank"}else{if((n??0)>0){let d=this.publication.getPreviousSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.left={href:f},this.api?.getContent(f).then(g=>{g===void 0?u?this.iframes[0].src=f:fetch(f,this.requestConfig).then(y=>y.text()).then(async y=>{o.call(this,y,f)}):o.call(this,g,f)})}}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(d=>{d===void 0?u?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{a.call(this,f,this.currentChapterLink.href)}):a.call(this,d,this.currentChapterLink.href)}))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.api?.getContent(this.currentChapterLink.href).then(d=>{d===void 0?u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{o.call(this,f,this.currentChapterLink.href)}):o.call(this,d,this.currentChapterLink.href)});else this.api?.getContent(this.currentChapterLink.href).then(d=>{this.currentSpreadLinks.left={href:this.currentChapterLink.href},d===void 0?u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{o.call(this,f,this.currentChapterLink.href)}):o.call(this,d,this.currentChapterLink.href)});else if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(u){if(this.iframes[0].src=this.currentChapterLink.href,this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.iframes.length===2)if((n??0)<this.publication.readingOrder.length-1){let d=this.publication.getNextSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.iframes[1].src=f,this.currentSpreadLinks.right={href:f}}}else this.iframes[1].src="about:blank"}else if(fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{o.call(this,d,this.currentChapterLink.href)}),this.iframes.length===2)if((n??0)<this.publication.readingOrder.length-1){let d=this.publication.getNextSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.right={href:f},fetch(f,this.requestConfig).then(g=>g.text()).then(async g=>{a.call(this,g,f)})}}else this.iframes[1].src="about:blank"}else{if((n??0)>0){let d=this.publication.getPreviousSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.left={href:f},u?(this.iframes[0].src=f,this.iframes.length===2&&(this.iframes[1].src=this.currentChapterLink.href)):(fetch(f,this.requestConfig).then(g=>g.text()).then(async g=>{o.call(this,g,f)}),this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},fetch(this.currentChapterLink.href,this.requestConfig).then(g=>g.text()).then(async g=>{a.call(this,g,this.currentChapterLink.href)})))}}else this.iframes[0].src="about:blank";this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},u?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{a.call(this,d,this.currentChapterLink.href)}))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{o.call(this,d,this.currentChapterLink.href)});else this.currentSpreadLinks.left={href:this.currentChapterLink.href},u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{o.call(this,d,this.currentChapterLink.href)});this.publication.isFixedLayout&&setTimeout(()=>{let d,f,g;if(n===0&&this.iframes?.length===2?g=this.iframes[1].contentDocument:g=this.iframes[0].contentDocument,g&&g.body&&(d=getComputedStyle(g.body).height,f=getComputedStyle(g.body).width,parseInt(d?.replace("px",""))===0||parseInt(f?.replace("px",""))===0)){let E=Qt(g,"head");if(E){let O=de(E,"meta[name=viewport]");if(O){var y=O.content,v=y.split(",").reduce((_,A)=>{var[T,M]=A.match(/[^\s;=]+/g);return _[T]=isNaN(Number(M))?M:+M,_},{});d=v.height+"px",f=v.width+"px"}}}var S=n===0&&this.iframes.length===2?this.iframes[1].parentElement?.parentElement:this.iframes[0].parentElement?.parentElement;if(S&&f){var w=(parseInt(getComputedStyle(S).width)-100)/(this.iframes.length===2?parseInt(f?.replace("px",""))*2+200:parseInt(f?.replace("px",""))),b=(parseInt(getComputedStyle(S).height)-100)/parseInt(d?.replace("px","")),m=Math.min(w,b);S.style.transform="scale("+m+")";for(let E of this.iframes)E.style.height=d,E.style.width=f,E.parentElement&&(E.parentElement.style.height=d)}},400)}static goBack(){window.history.back()}handleEditClick(t){var n=t.target;if(this.headerMenu){var r=de(document,".sidenav");n.className.indexOf(" active")===-1?(n.className+=" active",r.className+=" expanded",n.innerText="unfold_less",this.sideNavExpanded=!0,this.bookmarkModule?.showBookmarks(),this.annotationModule?.showHighlights()):(n.className=n.className.replace(" active",""),r.className=r.className.replace(" expanded",""),n.innerText="unfold_more",this.sideNavExpanded=!1,this.bookmarkModule?.showBookmarks(),this.annotationModule?.showHighlights())}t.preventDefault(),t.stopPropagation()}get hasMediaOverlays(){return this.publication.hasMediaOverlays}startReadAloud(){this.rights.enableTTS&&this.ttsModule.speakPlay()}startReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.startReadAloud()}stopReadAloud(){this.rights.enableTTS&&this.highlighter?.stopReadAloud()}stopReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.stopReadAloud()}pauseReadAloud(){this.rights.enableTTS&&(this.ttsModule.speakPause(),this.annotationModule!==void 0&&this.annotationModule.drawHighlights())}pauseReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.pauseReadAloud()}resumeReadAloud(){this.rights.enableTTS&&this.ttsModule.speakResume()}resumeReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.resumeReadAloud()}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 n=this.publication.getSpineItem(this.currentSpreadLinks.left.href),r=this.publication.getSpineItem(this.currentSpreadLinks.right.href);return[n,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()??!1}atEnd(){return this.view?.atEnd()??!1}previousPage(){this.handlePreviousPageClick(void 0)}nextPage(){this.handleNextPageClick(void 0)}previousResource(){this.handlePreviousChapterClick(void 0)}nextResource(){this.handleNextChapterClick(void 0)}goTo(t){let n=t.locations??{progression:0};if(t.href.indexOf("#")!==-1){let a=t.href.slice(t.href.indexOf("#")+1);a!==void 0&&(n=jt(Fe({},n),{fragment:a}))}let r=Fe({},t);r.locations=n;let o=this.publication.getAbsoluteHref(t.href);Yn.default.log(t.href),Yn.default.log(o),r.href=o,this.stopReadAloud(),this.navigate(r)}currentLocator(){let t;if(this.rights.autoGeneratePositions&&this.publication.positions||this.publication.positions){let n=this.publication.positionsByHref(this.publication.getRelativeHref(this.currentChapterLink.href)),r=Math.ceil((this.view?.getCurrentPosition()??0)*(n.length-1));t=n[r]}else{let n=this.publication.getTOCItem(this.currentChapterLink.href);n&&(this.currentTocUrl!==void 0&&(n=this.publication.getTOCItem(this.currentTocUrl)),n===void 0&&(n=this.publication.getTOCItemAbsolute(this.currentChapterLink.href)),n&&(t={href:n.Href,type:this.currentChapterLink.type,title:this.currentChapterLink.title,locations:{}}))}return t&&(t.locations.progression=this.view?.getCurrentPosition(),t.displayInfo={resourceScreenIndex:Math.round(this.view?.getCurrentPage()??0),resourceScreenCount:Math.round(this.view?.getPageCount()??0)}),t}positions(){return this.publication.positions?this.publication.positions:[]}goToPosition(t){if(this.publication.positions){let n=this.publication.positions.filter(r=>r.locations.position===parseInt(String(t)))[0];this.goTo(n)}}snapToSelector(t){let n=this.iframes[0].contentDocument;if(n){Yn.default.log(t);let r=n.querySelectorAll(t);r.length>0&&this.view?.snap(r[0])}}applyAttributes(t){this.attributes=t,this.view.attributes=t,this.handleResize()}handlePreviousPageClick(t){this.stopReadAloud(),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){let n=!0;if(this.sample?.isSampleRead&&this.publication.positions){let r=this.currentLocator(),o=Math.round((r.locations.totalProgression??0)*100);this.sample?.limit&&(n=o<=this.sample?.limit,this.view?.layout==="fixed"&&((!n&&this.sample?.minimum&&r.locations.position)??0<=(this.sample?.minimum??0))&&(n=!0))}(n&&this.sample?.isSampleRead&&this.publication.positions||!this.sample?.isSampleRead||!this.publication.positions)&&(this.stopReadAloud(),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()))),!n&&this.sample?.isSampleRead&&this.publication.positions&&t&&(t.preventDefault(),t.stopPropagation())}handleClickThrough(t){}handleInternalLink(t){let n=t.target,r={progression:0},o=n;if(o.href.indexOf("#")!==-1){let l=o.href.slice(o.href.indexOf("#")+1);l!==void 0&&(r={fragment:l})}let a={href:o.href,locations:r,type:o.type,title:o.title};t.preventDefault(),t.stopPropagation(),this.stopReadAloud(),this.navigate(a)}handleNumberOfIframes(){if(this.publication.isFixedLayout){if(this.settings.columnCount!==1&&!window.matchMedia("screen and (max-width: 600px)").matches){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 n=document.createElement("div");this.spreads.appendChild(n),n.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",n.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, 0% 120%)",n.style.boxShadow="0 0 8px 2px #ccc"}else this.iframes.length===2&&(this.iframes.pop(),this.spreads.lastChild&&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()}}async handleResize(){if(this.isScrolling)return;if(this.publication.isFixedLayout){var t=this.publication.getSpineIndex(this.currentChapterLink.href);let f=Fr()-40-(this.attributes?.margin??0);var n=t===0&&this.iframes.length===2?this.iframes[1].parentElement?.parentElement:this.iframes[0].parentElement?.parentElement;if(n){n.style.height=f+40+"px";let g,y,v;t===0&&this.iframes?.length===2?v=this.iframes[1].contentDocument:v=this.iframes[0].contentDocument,v&&v.body&&(g=getComputedStyle(v.body).height,y=getComputedStyle(v.body).width);let S=Qt(v,"head");if(S){let w=de(S,"meta[name=viewport]");if(w){var r=w.content,o=r.split(",").reduce((b,m)=>{var[E,O]=m.match(/[^\s;=]+/g);return b[E]=isNaN(Number(O))?O:+O,b},{});(parseInt(o.height)!==0||parseInt(o.width)!==0)&&(g=o.height+"px",y=o.width+"px")}}var a=(parseInt(getComputedStyle(n).width)-100)/(this.iframes.length===2?parseInt(y?.replace("px",""))*2+200:parseInt(y?.replace("px",""))),l=(parseInt(getComputedStyle(n).height)-100)/parseInt(g?.replace("px","")),u=Math.min(a,l);n.style.transform="scale("+u+")";for(let w of this.iframes)w.style.height=g,w.style.width=y,w.parentElement&&(w.parentElement.style.height=g)}}let d=this.view?.getCurrentPosition();await 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(f=>{f?(this.view.height=Fr()-40-(this.attributes?.margin??0),this.infoBottom&&this.infoBottom.style.removeProperty("display")):this.infoBottom&&(this.infoBottom.style.display="none")}),setTimeout(()=>{this.view?.layout!=="fixed"&&this.view?.isScrollMode()&&this.view?.setIframeHeight?.(this.iframes[0])},100),setTimeout(async()=>{d&&this.view?.goToProgression(d),await this.updatePositionInfo(!1),this.annotationModule!==void 0&&await this.annotationModule.handleResize(),this.bookmarkModule!==void 0&&await this.bookmarkModule.handleResize(),this.searchModule!==void 0&&await this.searchModule.handleResize(),this.definitionsModule!==void 0&&await this.definitionsModule.handleResize(),this.pageBreakModule!==void 0&&await this.pageBreakModule.handleResize(),this.contentProtectionModule!==void 0&&this.contentProtectionModule.handleResize(),this.lineFocusModule!==void 0&&this.lineFocusModule.handleResize(),this.historyModule!==void 0&&this.historyModule.handleResize()},150)}updatePositionInfo(t=!0){if(this.view?.layout==="fixed")this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");else if(this.view?.isPaginated()){let n=this.currentLocator();if(n){let r=n.displayInfo.resourceScreenIndex,o=n.displayInfo.resourceScreenCount;this.chapterPosition&&(this.chapterPosition.innerHTML="Page "+r+" of "+o)}}else this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");t&&this.savePosition()}handlePreviousChapterClick(t){if(this.view?.layout==="fixed"&&this.settings.columnCount!==1){let n=this.publication.getSpineIndex(this.currentChapterLink.href)??0;n=n-2,n<0&&(n=0);let r=this.publication.readingOrder[n],o={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(),this.navigate(o)}else if(this.previousChapterLink){let n={href:this.publication.getAbsoluteHref(this.previousChapterLink.href),locations:{progression:1},type:this.previousChapterLink.type,title:this.previousChapterLink.title};this.stopReadAloud(),this.navigate(n)}t&&(t.preventDefault(),t.stopPropagation())}handleNextChapterClick(t){if(this.view?.layout==="fixed"&&this.settings.columnCount!==1){let n=this.publication.getSpineIndex(this.currentChapterLink.href)??0;n=n+2,n>=this.publication.readingOrder.length-1&&(n=this.publication.readingOrder.length-1);let r=this.publication.readingOrder[n],o={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(),this.navigate(o)}else if(this.nextChapterLink){let n={href:this.publication.getAbsoluteHref(this.nextChapterLink.href),locations:{progression:0},type:this.nextChapterLink.type,title:this.nextChapterLink.title};this.stopReadAloud(),this.navigate(n)}t&&(t.preventDefault(),t.stopPropagation())}hideView(){this.view?.layout!=="fixed"&&this.view?.isScrollMode()&&(document.body.style.overflow="auto")}setActiveTOCItem(t){if(this.tocView){let n=Array.prototype.slice.call(this.tocView.querySelectorAll("li > a"));for(let o of n)o.className=o.className.replace(" active","");let r=this.tocView.querySelector('li > a[href^="'+t+'"]');r&&(r.className+=" active")}}async navigate(t,n=!0){if(this.historyModule&&this.historyModule.push(t,n),this.publication.getTOCItem(t.href)){var o=!1;if(t.href.indexOf("#")!==-1){let a=t.href.slice(0,t.href.indexOf("#"));a===this.currentChapterLink.href&&(o=!0),this.currentChapterLink.href=a,this.currentChapterLink.type=t.type,this.currentChapterLink.title=t.title}else t.href===this.currentChapterLink.href&&(o=!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(o){if(t.href.indexOf("#")!==-1){let g=t.href.slice(t.href.indexOf("#")+1);t.locations={fragment:g}}if(this.newPosition=t,this.currentTOCRawLink=t.href,t.locations.fragment===void 0?this.currentTocUrl=void 0:(this.newElementId=t.locations.fragment,this.currentTocUrl=this.currentChapterLink.href+"#"+this.newElementId),this.newElementId){for(let g of this.iframes){let y=g.contentDocument.getElementById(this.newElementId);this.view?.goToElement?.(y)}this.newElementId=void 0}else if(t.highlight){let g=t.highlight?.selectionInfo.rangeInfo.startContainerElementCssSelector;g&&this.view?.goToCssSelector(g)}else this.view?.goToProgression(t.locations.progression??0);let a=this.currentChapterLink.href,l=this.publication.getPreviousSpineItem(a);l&&l.Href&&(this.previousChapterLink={href:l.Href,type:l.TypeLink,title:l.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 u=this.publication.getNextSpineItem(a);u?this.nextChapterLink={href:u.Href,type:u.TypeLink,title:u.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!==void 0?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(a),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let d=this.publication.getSpineItem(a);d!==void 0&&(this.currentChapterLink.title=d.Title,this.currentChapterLink.type=d.TypeLink);let f=this.publication.getTOCItem(a);this.currentTocUrl!==void 0&&(f=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&f!==void 0&&f.Title&&(this.currentChapterLink.title=f.Title),!this.currentChapterLink.type&&f!==void 0&&f.TypeLink&&(this.currentChapterLink.title=f.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),await this.updatePositionInfo()}else this.lineFocusModule!==void 0&&this.lineFocusModule.disableLineFocus(!1),this.searchModule!==void 0&&this.searchModule.clearSearch(),t.locations.fragment===void 0?this.currentTocUrl=void 0:(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(),this.rights.enableContentProtection&&this.contentProtectionModule!==void 0&&await this.contentProtectionModule.initializeResource(),this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&await this.mediaOverlayModule.initializeResource(this.currentLink()),this.rights.enableContentProtection&&this.contentProtectionModule!==void 0&&this.contentProtectionModule.recalculate(300),this.annotationModule!==void 0&&(await this.annotationModule.drawHighlights(),await this.annotationModule.showHighlights()),this.bookmarkModule!==void 0&&(await this.bookmarkModule.drawBookmarks(),await this.bookmarkModule.showBookmarks()),this.pageBreakModule!==void 0&&(await this.highlighter?.destroyHighlights(qe.PageBreak),await this.pageBreakModule.drawPageBreaks()),this.rights.enableSearch&&this.searchModule!==void 0&&this.highlighter!==void 0&&(await this.highlighter.destroyHighlights(qe.Search),this.searchModule.drawSearch()),this.rights.enableDefinitions&&this.definitionsModule!==void 0&&this.highlighter!==void 0&&this.definitionsModule.drawDefinitions(),this.view?.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.api?.resourceFitsScreen&&this.api?.resourceFitsScreen(),this.emit("resource.fits")):this.settings.isPaginated().then(a=>{a||(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 a=this.publication.getStartLink(),l;if(a&&a.Href&&(l=this.publication.getAbsoluteHref(a.Href),l)){let u={href:l,locations:{progression:0},created:new Date,title:a.Title};await this.navigate(u)}}}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")),this.mediaOverlayModule!==void 0&&(this.mediaOverlayModule.settings.resourceReady=!1)}hideIframeContents(){this.isBeingStyled=!0,this.iframes.forEach(t=>{t.style.opacity="0",t.style.border="none",t.style.overflow="hidden"})}hideLoadingMessage(){setTimeout(()=>{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()?(this.api?.resourceFitsScreen&&this.api?.resourceFitsScreen(),this.emit("resource.fits")):this.view?.atEnd()?(this.api?.resourceAtEnd&&this.api?.resourceAtEnd(),this.emit("resource.end")):this.view?.atStart()&&(this.api?.resourceAtStart&&this.api?.resourceAtStart(),this.emit("resource.start"))),this.api?.resourceReady&&this.api?.resourceReady(),this.emit("resource.ready")},150)}saveCurrentReadingPosition(){if(this.annotator){var t=this.publication.getTOCItem(this.currentChapterLink.href);this.currentTocUrl!==void 0&&(t=this.publication.getTOCItem(this.currentTocUrl)),t===void 0&&(t=this.publication.getTOCItemAbsolute(this.currentChapterLink.href));let n={progression:this.view?.getCurrentPosition()};if(t){if(t.Href.indexOf("#")!==-1){let o=t.Href.slice(t.Href.indexOf("#")+1);o!==void 0&&(n={progression:this.view?.getCurrentPosition(),fragment:o})}let r;if(this.rights.autoGeneratePositions&&this.publication.positions||this.publication.positions){let o=this.publication.positionsByHref(this.publication.getRelativeHref(t.Href));if(o.length>0){let a=Math.ceil((n.progression??0)*(o.length-1)),l=o[a];l&&(l.locations.fragment=n.fragment,r=jt(Fe({},l),{href:t.Href,created:new Date,title:this.currentChapterLink.title}))}}else r={href:t.Href,locations:n,created:new Date,type:this.currentChapterLink.type,title:this.currentChapterLink.title};r&&(this.sample?.isSampleRead&&this.publication.positions&&this.sampleReadEventHandler?.enforceSampleRead(r),this.api?.updateCurrentLocation?this.api?.updateCurrentLocation(r).then(async o=>(Yn.default.log("api updated current location",r),this.annotator?.saveLastReadingPosition(r))):(Yn.default.log("save last reading position",r),this.annotator.saveLastReadingPosition(r)))}}}static createBase(t){let n=document.createElement("base");return n.target="_self",n.href=t,n}static createCssLink(t){let n=document.createElement("link");return n.rel="stylesheet",n.type="text/css",n.href=t,n}static createJavascriptLink(t,n){let r=document.createElement("script");return r.type="text/javascript",r.src=t,r.async=n,r}activateMarker(t,n){this.annotationModule!==void 0&&(this.annotationModule.activeAnnotationMarkerId===void 0||this.annotationModule.activeAnnotationMarkerId!==t?(this.annotationModule.activeAnnotationMarkerId=t,this.annotationModule.activeAnnotationMarkerPosition=n,this.highlighter&&(this.highlighter.activeAnnotationMarkerId=t)):this.deactivateMarker())}deactivateMarker(){this.annotationModule!==void 0&&(this.annotationModule.activeAnnotationMarkerId=void 0,this.annotationModule.activeAnnotationMarkerPosition=void 0,this.highlighter&&(this.highlighter.activeAnnotationMarkerId=void 0))}showLayer(t){let n="#",r=new xa("layer-on","layer-off",!0,t,"layer-"+t);switch(t){case"annotations":case"highlights":n+=Re.R2_ID_HIGHLIGHTS_CONTAINER,r.name=Re.R2_ID_HIGHLIGHTS_CONTAINER;break;case"readaloud":n+=Re.R2_ID_READALOUD_CONTAINER,r.name=Re.R2_ID_READALOUD_CONTAINER;break;case"pagebreak":n+=Re.R2_ID_PAGEBREAK_CONTAINER,r.name=Re.R2_ID_PAGEBREAK_CONTAINER;break;case"search":n+=Re.R2_ID_SEARCH_CONTAINER,r.name=Re.R2_ID_SEARCH_CONTAINER;break;case"definitions":n+=Re.R2_ID_DEFINITIONS_CONTAINER,r.name=Re.R2_ID_DEFINITIONS_CONTAINER;break}this.highlighter?.layerSettings.saveProperty(r);let o=this.iframes[0].contentDocument;if(o){let a=de(o,n);a&&(a.style.display="block")}}hideLayer(t){let n="#",r=new xa("layer-on","layer-off",!1,t,"layer-"+t);switch(t){case"annotations":case"highlights":n+=Re.R2_ID_HIGHLIGHTS_CONTAINER,r.name=Re.R2_ID_HIGHLIGHTS_CONTAINER;break;case"readaloud":n+=Re.R2_ID_READALOUD_CONTAINER,r.name=Re.R2_ID_READALOUD_CONTAINER;break;case"pagebreak":n+=Re.R2_ID_PAGEBREAK_CONTAINER,r.name=Re.R2_ID_PAGEBREAK_CONTAINER;break;case"search":n+=Re.R2_ID_SEARCH_CONTAINER,r.name=Re.R2_ID_SEARCH_CONTAINER;break;case"definitions":n+=Re.R2_ID_DEFINITIONS_CONTAINER,r.name=Re.R2_ID_DEFINITIONS_CONTAINER;break}this.highlighter?.layerSettings.saveProperty(r);let o=this.iframes[0].contentDocument;if(o){let a=de(o,n);a&&(a.style.display="none")}}};C();var yt=class{constructor(t){this.store=t.store}getLastReadingPosition(){let t=this.store.get(yt.LAST_READING_POSITION);return t?JSON.parse(t):null}initLastReadingPosition(t){if(typeof t=="string")this.store.set(yt.LAST_READING_POSITION,t);else{let n=JSON.stringify(t);this.store.set(yt.LAST_READING_POSITION,n)}}saveLastReadingPosition(t){if(typeof t=="string")this.store.set(yt.LAST_READING_POSITION,t);else{let n=JSON.stringify(t);this.store.set(yt.LAST_READING_POSITION,n)}}initBookmarks(t){if(typeof t=="string"){let n=JSON.parse(t);this.store.set(yt.BOOKMARKS,JSON.stringify(n))}else this.store.set(yt.BOOKMARKS,JSON.stringify(t));return t}saveBookmark(t){let n=this.store.get(yt.BOOKMARKS);if(n){let r=JSON.parse(n);r.push(t),this.store.set(yt.BOOKMARKS,JSON.stringify(r))}else{let r=[];r.push(t),this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return t}locatorExists(t,n){let r;switch(n){case fr.Bookmark:r=yt.BOOKMARKS;break}let o=this.store.get(r);return o&&JSON.parse(o).filter(u=>u.href===t.href&&u.locations.progression===t.locations.progression).length>0?t:null}deleteBookmark(t){let n=this.store.get(yt.BOOKMARKS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.id!==t.id),this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return t}getBookmarks(t){let n=this.store.get(yt.BOOKMARKS);if(n){let r=JSON.parse(n);if(t){let o=r.filter(a=>a.href===t);return o=o.sort((a,l)=>{if(a.locations.progression&&l.locations.progression)return a.locations.progression-l.locations.progression}),o}return r=r.sort((o,a)=>{if(o.locations.progression&&a.locations.progression)return o.locations.progression-a.locations.progression}),r}return[]}initAnnotations(t){let n;typeof t=="string"?n=JSON.parse(t):n=t;let r=[];return n.forEach(o=>{let a=`${o.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector}${o.highlight.selectionInfo.rangeInfo.startContainerChildTextNodeIndex}${o.highlight.selectionInfo.rangeInfo.startOffset}${o.highlight.selectionInfo.rangeInfo.endContainerElementCssSelector}${o.highlight.selectionInfo.rangeInfo.endContainerChildTextNodeIndex}${o.highlight.selectionInfo.rangeInfo.endOffset}`,l=Tr.hash(a);o.highlight.id="R2_HIGHLIGHT_"+l;let u;o.highlight.color?u=o.highlight.color:o.color&&(u=o.color),De.isHexColor(u)&&(u=De.hexToRgbString(u)),o.highlight.color=u,o.highlight.pointerInteraction=!0,o.highlight.selectionInfo.cleanText=o.highlight.selectionInfo.rawText.trim().replace(/\n/g," ").replace(/\s\s+/g," "),r.push(o)}),this.store.set(yt.ANNOTATIONS,JSON.stringify(r)),r}saveTemporarySelectionInfo(t){this.store.set(yt.SELECTIONINFO,JSON.stringify(t))}getTemporarySelectionInfo(t){let n=this.store.get(yt.SELECTIONINFO);if(n){let r=JSON.parse(n);return r.range=vd(t,r.rangeInfo),r}return[]}deleteTemporarySelectionInfo(){this.store.remove(yt.SELECTIONINFO)}saveAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let r=JSON.parse(n);r.push(t),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}else{let r=[];r.push(t),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return t}deleteAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.id!==t),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return t}deleteSelectedAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.highlight?.id!==t.highlight.id),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return t}getAnnotations(){let t=this.store.get(yt.ANNOTATIONS);if(t){let n=JSON.parse(t);return n=n.sort((r,o)=>{if(r.locations.progression&&o.locations.progression)return r.locations.progression-o.locations.progression}),n}return[]}getAnnotationPosition(t,n){let r=this.store.get(yt.ANNOTATIONS);if(r){let a=JSON.parse(r).filter(l=>l.highlight?.id===t||l.id===t);if(a.length>0){let l=n.document.getElementById(`${a[0].highlight.id}`);if(l){let u=0;if(l.hasChildNodes)for(let d=0;d<l.childNodes.length;d++){let f=l.childNodes[d],g=parseInt(f.style.top.replace("px",""));(g<u||u===0)&&(u=g)}else u=parseInt(l.style.top.replace("px",""));return u}}}return null}getAnnotationElement(t,n){let r=this.store.get(yt.ANNOTATIONS);if(r){let a=JSON.parse(r).filter(l=>l.highlight?.id===t);if(a.length>0){let l=n.document.getElementById(`${a[0].highlight.id}`);if(l){let u=0;if(l.hasChildNodes)for(let d=0;d<l.childNodes.length;d++){let f=l.childNodes[d],g=parseInt(f.style.top.replace("px",""));if(g<u||u===0)return u=g,f}else u=parseInt(l.style.top.replace("px",""));return l}}}return null}getAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let o=JSON.parse(n).filter(a=>a.highlight?.id===t.id);if(o.length>0)return o[0]}return null}getAnnotationByID(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let o=JSON.parse(n).filter(a=>a.highlight?.id===t);if(o.length>0)return o[0]}return null}},lo=yt;lo.LAST_READING_POSITION="last-reading-position",lo.BOOKMARKS="bookmarks",lo.ANNOTATIONS="annotations",lo.SELECTIONINFO="selectionInfo";C();C();var Wd=class{constructor(){this.store={}}get(t){return this.store[t]||null}set(t,n){this.store[t]=n}remove(t){this.store[t]=null}};var Ys=class{constructor(t){this.prefix=t.prefix,this.useLocalStorage=t.useLocalStorage;try{let n=t.prefix+"-"+String(Math.random());this.useLocalStorage?(window.localStorage.setItem(n,"test"),window.localStorage.removeItem(n)):(window.sessionStorage.setItem(n,"test"),window.sessionStorage.removeItem(n)),this.fallbackStore=null}catch(n){this.fallbackStore=new Wd}}getLocalStorageKey(t){return this.prefix+"-"+t}get(t){let n;return this.fallbackStore?n=this.fallbackStore.get(t):this.useLocalStorage?n=window.localStorage.getItem(this.getLocalStorageKey(t)):n=window.sessionStorage.getItem(this.getLocalStorageKey(t)),n}set(t,n){this.fallbackStore?this.fallbackStore.set(t,n):this.useLocalStorage?window.localStorage.setItem(this.getLocalStorageKey(t),n):window.sessionStorage.setItem(this.getLocalStorageKey(t),n)}remove(t){this.fallbackStore?this.fallbackStore.remove(t):this.useLocalStorage?window.localStorage.removeItem(this.getLocalStorageKey(t)):window.sessionStorage.removeItem(this.getLocalStorageKey(t))}};C();var P3=Je(va()),I3=Je(Cn());var sl=class extends P3.Link{};sl=ac([(0,I3.JsonObject)()],sl);function al(i){let t,n,r,o;if(i instanceof Array)return i.map(function(a){return typeof a=="object"&&(a=al(a)),a});t={};for(n in i)i.hasOwnProperty(n)&&(r=(n.charAt(0).toLowerCase()+n.slice(1)||n).toString(),o=i[n],(o instanceof Array||o!==null&&o.constructor===Object)&&(o=al(o)),r==="href1"?t.href=o:r==="typeLink"?t.type=o:t[r]=o);return t}C();var L3=Je(Dt()),ig=class{constructor(t){this.LAYERSETTINGS="layerSetting";this.store=t,this.initialize()}static async create(t){let n=new this(t.store);return new Promise(r=>r(n))}async stop(){L3.default.log("MediaOverlay settings stop")}async initialize(){this.userProperties=await this.getLayerSettings()}async getLayerSettings(){let t=new Si,n=await this.store.get(this.LAYERSETTINGS);if(n){let r=JSON.parse(n);t.properties=r}return t}async saveProperty(t){let n=await this.store.get(this.LAYERSETTINGS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.name!==t.name),r.push(t),await this.store.set(this.LAYERSETTINGS,JSON.stringify(r))}else{let r=[];r.push(t),await this.store.set(this.LAYERSETTINGS,JSON.stringify(r))}return new Promise(r=>r(t))}async getProperty(t){let n=await this.store.get(this.LAYERSETTINGS);if(n){let r=JSON.parse(n);return r=r.filter(o=>o.name===t),r.length===0?null:r[0]}return null}};C();var ll=Je(Dt()),og=class{static async create(t){let n=new this(t.delegate,t.publication,t,t.headerMenu);return await n.start(),n}constructor(t,n,r,o){this.headerMenu=o,this.delegate=t,this.publication=n,this.properties=r}async stop(){ll.default.log("Page Break module stop")}async start(){this.delegate.pageBreakModule=this,this.headerMenu&&(this.goToPageView=de(this.headerMenu,"#sidenav-section-gotopage")),this.headerMenu&&(this.goToPageNumberInput=de(this.headerMenu,"#goToPageNumberInput")),this.headerMenu&&(this.goToPageNumberButton=de(this.headerMenu,"#goToPageNumberButton")),ne(this.goToPageNumberInput,"keypress",this.goToPageNumber.bind(this)),ne(this.goToPageNumberButton,"click",this.goToPageNumber.bind(this)),this.goToPageView&&(this.publication.pageList?.length||this.goToPageView.parentElement?.removeChild(this.goToPageView)),setTimeout(()=>{this.properties.hideLayer?this.delegate.hideLayer("pagebreak"):this.delegate.showLayer("pagebreak")},10)}async goToPageNumber(t){if(this.goToPageNumberInput.value&&(t.key==="Enter"||t.type==="click")){var n=this.publication.pageList?.filter(o=>o.Href.slice(o.Href.indexOf("#")+1).replace(/[^0-9]/g,"")===this.goToPageNumberInput.value);if(n&&n.length>0){var r=n[0];let o={progression:0};if(r.Href.indexOf("#")!==-1){let l=r.Href.slice(r.Href.indexOf("#")+1);l!==null&&(o={fragment:l})}let a={href:this.publication.getAbsoluteHref(r.Href),locations:o,type:r.TypeLink,title:r.Title};this.delegate.goTo(a)}}}async handleResize(){await this.delegate.highlighter?.destroyHighlights(qe.PageBreak),await this.drawPageBreaks()}async drawPageBreaks(){setTimeout(()=>{let t=this.delegate.iframes[0].contentDocument?.body,n=t?.querySelectorAll('[*|type="pagebreak"]');n?.length===0&&(n=t?.querySelectorAll("[epub\\:type='pagebreak']"));let r=this;function o(a){try{let l=r.delegate.iframes[0].contentDocument;return l?Rn(a,l,no):""}catch(l){return ll.default.log("uniqueCssSelector:"),ll.default.error(l),""}}if(n)for(let a=0;a<n.length;a++){let l=n[a];ll.default.log(l);let u=l.innerHTML,d=!1;l.innerHTML.length===0&&(u=l.getAttribute("title")??"",l.innerHTML=u,d=!0),l.innerHTML.length===0&&(u=(l.getAttribute("id")??"").replace(/[^0-9]/g,""),l.innerHTML=u,d=!0);let f=this.delegate.iframes[0].contentDocument;if(f){let g=this.delegate.highlighter?.dom(f.body).getWindow().document.createRange(),y=this.delegate.highlighter?.dom(f.body).getSelection();if(y.removeAllRanges(),g.selectNodeContents(l),y.addRange(g),!y.isCollapsed){let v=Ri(g,o);y.removeAllRanges(),v&&this.createPageBreakHighlight({rangeInfo:v,cleanText:"",rawText:""},u)}}d&&(l.innerHTML="")}},200)}createPageBreakHighlight(t,n){try{let o=`${t.rangeInfo.startContainerElementCssSelector}${t.rangeInfo.startContainerChildTextNodeIndex}${t.rangeInfo.startOffset}${t.rangeInfo.endContainerElementCssSelector}${t.rangeInfo.endContainerChildTextNodeIndex}${t.rangeInfo.endOffset}`,a=Tr.hash(o),l="R2_PAGEBREAK_"+a;var r=!1;let u={color:"#000000",id:l,pointerInteraction:r,selectionInfo:t,marker:Le.Custom,icon:{id:"pageBreak",title:n,color:"#000000",position:"left"},type:qe.PageBreak};zt.push(u);let d=this.delegate.highlighter?.createHighlightDom(this.delegate.iframes[0].contentWindow,u);return u.position=parseInt((d?.hasChildNodes()?d.childNodes[0]:d).style.top.replace("px","")),u}catch(o){throw"Can't create highlight: "+o}}};C();var B3=Je(Xp());var k3=Je(Qi());var Ke=Je(Dt()),sg=class{constructor(t,n,r,o,a,l,u){this.voices=[];this.hasEventListener=!1;this.startX=0;this.startY=0;this.index=0;this.userScrolled=!1;this.scrollPartial=!1;this.speaking=!1;this.restartIndex=-1;this.ttsQueueIndex=-1;this.ttsQueue=void 0;this.ttsPlayQueueIndexDebounced=(0,k3.debounce)((t,n)=>{this.restartIndex>=0?(this.ttsQueueIndex=this.restartIndex,this.restartIndex=-1):this.ttsQueueIndex=t,this.ttsQueue=n,this.ttsPlayQueueIndex(this.ttsQueueIndex,n)},150);this.delegate=t,this.tts=n,this.headerMenu=u,this.rights=r,this.highlighter=o,this.properties=a,this.api=l}initialize(t){this.highlighter!==void 0&&(this.tts.setControls(),this.tts.onRestart(this.restart.bind(this)),this.body=t,this.clean=(0,B3.default)(this.body.innerHTML,{allowedTags:[],allowedAttributes:{}}),this.wrapper=dt(document,"#iframe-wrapper"),window.speechSynthesis.getVoices(),this.initVoices(!0),this.hasEventListener||(this.hasEventListener=!0,ne(document,"wheel",this.wheel.bind(this)),ne(this.body,"wheel",this.wheel.bind(this)),ne(document,"keydown",this.wheel.bind(this)),ne(this.delegate.iframes[0].contentDocument,"keydown",this.wheel.bind(this))),ne(this.body,"mousedown",this.clickStart.bind(this)),ne(this.body,"mouseup",this.click.bind(this)))}clickStart(t){"clientX"in t&&(this.startX=t.clientX),"clientY"in t&&(this.startY=t.clientY)}click(t){let n=0,r=0;if("clientX"in t&&(n=t.clientX),"clientY"in t&&(r=t.clientY),window.speechSynthesis.speaking&&this.speaking&&n===this.startX&&r===this.startY){let o=this.delegate.iframes[0].contentDocument;if(o){let a=this.highlighter.dom(o.body).getSelection();if(a.isCollapsed){let g=this.delegate.iframes[0].contentDocument,y=this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(g);a.addRange(y.range)}let l=a.getRangeAt(0),u=a.anchorNode;for(;l.toString().indexOf(" ")!==0;)try{l.setStart(u,l.startOffset-1)}catch(g){break}l.setStart(u,l.startOffset+1);do l.setEnd(u,u.length<l.endOffset?l.endOffset+1:u.length);while(l.toString().indexOf(" ")===-1&&l.toString().trim()!=="");let f=document.querySelector("main#iframe-wrapper iframe").contentWindow?.document.body;if(this.ttsQueue&&f){let g=this.findTtsQueueItemIndex(this.ttsQueue,a.anchorNode,a.anchorNode,a.anchorOffset,f);a.removeAllRanges(),g>=0&&(window.speechSynthesis.cancel(),this.restartIndex=g,this.ttsPlayQueueIndexDebounced(this.restartIndex,this.ttsQueue))}}}}initVoices(t){function n(){return new Promise(function(o,a){let l=window.speechSynthesis,u;u=setInterval(()=>{l.getVoices().length!==0&&(o(l.getVoices()),clearInterval(u))},10)})}n().then(async o=>{if(Ke.default.log(o),this.voices=[],o.forEach(l=>{l.localService===!0&&this.voices.push(l)}),Ke.default.log(this.voices),t&&this.headerMenu){var a=de(this.headerMenu,"#preferred-languages");a&&this.voices.forEach(l=>{var u=document.createElement("option");u.value=l.name+":"+l.lang,u.innerHTML=l.name+" ("+l.lang+")",a.add(u)})}})}cancel(t=!0){t&&(this.api?.stopped&&this.api?.stopped(),this.delegate.emit("readaloud.stopped","stopped")),this.userScrolled=!1,this.speaking=!1,setTimeout(()=>{window.speechSynthesis.cancel()},0),this._ttsQueueItemHighlightsWord&&(this.delegate.highlighter?.destroyHighlights(qe.ReadAloud),this._ttsQueueItemHighlightsWord=void 0)}async speak(t,n,r){this.api?.started&&this.api?.started(),this.delegate.emit("readaloud.started","started");let o=this;this.userScrolled=!1,this.cancel(!1);let a;if(n){let O=document.querySelector("main#iframe-wrapper iframe").contentWindow?.document.body,_=this.delegate.iframes[0].contentDocument;if(_){let A=this.highlighter.dom(_.body).getSelection();if(A.isCollapsed){let T=o.delegate.iframes[0].contentDocument,M=o.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(T);A.addRange(M.range)}if(O){var l=this.generateTtsQueue(O);if(!l.length)return;var u=this.findTtsQueueItemIndex(l,A.anchorNode,A.anchorNode,A.anchorOffset,O),d=this.findTtsQueueItemIndex(l,A.focusNode,A.focusNode,A.focusOffset,O);let T=Vo(l,u),M=Vo(l,d);var f;if(T&&t&&t.cleanText){let j=Jo(T),P=t.rangeInfo.startOffset,q=t.cleanText;if(M&&u+1===d){let k=Jo(M);P=(j+" "+k).indexOf(t.cleanText),q=j.slice(P,j.length),f=t.cleanText.replace(q,"").trim()}else if(d>u){let k="";for(let B=u+1;B<d;B++){let N=Vo(l,B);if(N){let W=Jo(N);k+=W,f=t.cleanText.replace(W,"")}}if(M){let B=Jo(M);k+=" "+B}P=(j+" "+k).indexOf(t.cleanText),q=j.slice(P,j.length),f=f.replace(q,"").trim()}a=new SpeechSynthesisUtterance(q),Ke.default.log(t),Ke.default.log(q,t.range?.commonAncestorContainer.textContent),Ke.default.log(T),Ke.default.log(T.item.textNodes),Ke.default.log(P),Ke.default.log(T.item.combinedText);let U=T.item.textNodes.filter(k=>k===t.range?.commonAncestorContainer)[0];Ke.default.log(U),a.onboundary=k=>{this.updateTTSInfo(T,k.charIndex,k.charLength,P,a.text)}}}}}else a=new SpeechSynthesisUtterance(this.clean);a.rate=this.tts.rate,a.pitch=this.tts.pitch,a.volume=this.tts.volume,Ke.default.log("this.tts.voice.lang",this.tts.voice.lang);var g=!0;this.tts.voice&&this.tts.voice.lang&&(g=this.tts.voice.lang.indexOf("-")!==-1,g===!1&&(this.tts.voice.lang=this.tts.voice.lang.replace("_","-"),g=!0)),Ke.default.log("initialVoiceHasHyphen",g),Ke.default.log("voices",this.voices);var y;g===!0?(y=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(E=>{var O=E.lang.replace("_","-");return O===this.tts.voice.lang&&E.name===this.tts.voice.name})[0]:void 0,y===void 0&&(y=this.tts.voice&&this.tts.voice.lang?this.voices.filter(E=>E.lang.replace("_","-")===this.tts.voice.lang)[0]:void 0)):(y=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(E=>E.lang===this.tts.voice.lang&&E.name===this.tts.voice.name)[0]:void 0,y===void 0&&(y=this.tts.voice&&this.tts.voice.lang?this.voices.filter(E=>E.lang===this.tts.voice.lang)[0]:void 0)),Ke.default.log("initialVoice",y);var v=o.delegate.publication.Metadata.Language[0].indexOf("-")!==-1;Ke.default.log("publicationVoiceHasHyphen",v);var S;v===!0?S=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(E=>{var O=E.lang.replace("_","-");return O.startsWith(o.delegate.publication.Metadata.Language[0])||O.endsWith(o.delegate.publication.Metadata.Language[0].toUpperCase())})[0]:void 0:S=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(E=>E.lang.startsWith(o.delegate.publication.Metadata.Language[0])||E.lang.endsWith(o.delegate.publication.Metadata.Language[0].toUpperCase()))[0]:void 0,Ke.default.log("publicationVoice",S);var w=navigator.language.indexOf("-")!==-1;Ke.default.log("defaultVoiceHasHyphen",w);var b;w===!0?b=this.voices.filter(E=>{var O=E.lang.replace("_","-");return O===navigator.language&&E.localService===!0})[0]:b=this.voices.filter(E=>{var O=E.lang;return O===navigator.language&&E.localService===!0})[0],b===void 0&&(b=this.voices.filter(E=>{var O=E.lang;return O.includes(navigator.language)&&E.localService===!0})[0]),Ke.default.log("defaultVoice",b),y?(Ke.default.log("initialVoice"),a.voice=y):S?(Ke.default.log("publicationVoice"),a.voice=S):b&&(Ke.default.log("defaultVoice"),a.voice=b),a.voice!==void 0&&a.voice!==null&&(a.lang=a.voice.lang,Ke.default.log("utterance.voice.lang",a.voice.lang),Ke.default.log("utterance.lang",a.lang)),Ke.default.log("navigator.language",navigator.language),setTimeout(()=>{window.speechSynthesis.speak(a)},0),this.index=0;function m(){a.onend=function(){if(d>u)if(u=u+1,u!==d){let E=Vo(l,u);if(E){let O=Jo(E);a=new SpeechSynthesisUtterance(O),a.onboundary=_=>{o.updateTTSInfo(E,_.charIndex,_.charLength,0,a.text)},setTimeout(()=>{window.speechSynthesis.speak(a)},0),m()}}else{let E=Vo(l,u);E&&(a=new SpeechSynthesisUtterance(f),a.onboundary=O=>{o.updateTTSInfo(E,O.charIndex,O.charLength,0,a.text)},setTimeout(()=>{window.speechSynthesis.speak(a)},0),m()),u>d&&(Ke.default.log("utterance ended"),o.highlighter.doneSpeaking(),o.api?.finished(),o.delegate.emit("readaloud.finished","finished"))}else Ke.default.log("utterance ended"),o.highlighter.doneSpeaking(),o.api?.finished(),o.delegate.emit("readaloud.finished","finished")}}m(),r()}speakPlay(){this.scrollPartial=!0,this.cancel(!1),this.api?.started&&this.api?.started(),this.delegate.emit("readaloud.started","started");let t=this,r=document.querySelector("main#iframe-wrapper iframe").contentWindow?.document.body;if(r){let l=function(){let u=t.highlighter.visibleTextRects[0],d=t.delegate.iframes[0].contentDocument;if(d){let f=t.highlighter.dom(d.body).getWindow().document.createRange(),g=t.highlighter.dom(t.delegate.iframes[0].contentDocument?.body).getSelection();g.removeAllRanges(),f.selectNodeContents(u.node),g.addRange(f);let y=0,v=g.focusNode,S=g.focusOffset;g.collapse(g.anchorNode,g.anchorOffset);for(let w=0;w<y;w++)g.modify("move","forward","line");if(g.extend(v,S),g.collapse(g.anchorNode,g.anchorOffset),r){let w=t.findTtsQueueItemIndex(o,g.anchorNode,g.anchorNode,g.anchorOffset,r);w>=0&&(a=w)}g.removeAllRanges()}},o=this.generateTtsQueue(r);if(!o.length)return;let a=0;l(),a<0&&(a=0),setTimeout(()=>{this.startTTSSession(o,a)},200)}}speakPause(){window.speechSynthesis.speaking&&(this.api?.paused&&this.api?.paused(),this.delegate.emit("readaloud.paused","paused"),this.userScrolled=!1,window.speechSynthesis.pause(),this.speaking=!1,this._ttsQueueItemHighlightsWord&&(this.delegate.highlighter?.destroyHighlights(qe.ReadAloud),this._ttsQueueItemHighlightsWord=void 0))}speakResume(){window.speechSynthesis.speaking&&(this.api?.resumed&&this.api?.resumed(),this.delegate.emit("readaloud.resumed","resumed"),this.userScrolled=!1,window.speechSynthesis.resume(),this.speaking=!0)}static async create(t){let n=new this(t.delegate,t.tts,t.rights,t.highlighter,t,t.api,t.headerMenu);return await n.start(),n}async start(){if(this.delegate.ttsModule=this,this.headerMenu){var t=de(this.headerMenu,"#menu-button-tts");t&&t.parentElement?.style.removeProperty("display")}setTimeout(()=>{this.properties?.hideLayer?this.delegate.hideLayer("readaloud"):this.delegate.showLayer("readaloud")},10)}wheel(t){if(t instanceof KeyboardEvent)switch(t.key){case"ArrowUp":this.userScrolled=!0;break;case"ArrowDown":this.userScrolled=!0;break}else this.userScrolled=!0}stop(){Ke.default.log("TTS module stop"),Pe(document,"wheel",this.wheel.bind(this)),Pe(this.body,"wheel",this.wheel.bind(this)),Pe(document,"keydown",this.wheel.bind(this)),Pe(this.delegate.iframes[0].contentDocument,"keydown",this.wheel.bind(this)),Pe(this.body,"click",this.click.bind(this))}generateTtsQueue(t){let n=[],r=[];function o(d){if(d.nodeType!==Node.TEXT_NODE||!d.nodeValue||!d.nodeValue.trim().length)return;let f=r[r.length-1];if(!f)return;let g=d.parentElement?N3(d.parentElement):void 0,y=d.parentElement?aN(d.parentElement):void 0,v=n[n.length-1];(!v||v.parentElement!==f||v.lang!==g||v.dir!==y)&&(v={combinedText:"",dir:y,lang:g,parentElement:f,textNodes:[]},n.push(v)),v.textNodes.push(d)}let a=!0;function l(d){if(d.nodeType!==Node.ELEMENT_NODE)return;let f=a||d.matches("h1, h2, h3, h4, h5, h6, p, th, td, caption, li, blockquote, q, dt, dd, figcaption, div, pre");a=!1,f&&r.push(d);for(let g of d.childNodes)switch(g.nodeType){case Node.ELEMENT_NODE:let y=g;if(!y.matches("img, sup, sub, audio, video, source, button, canvas, del, dialog, embed, form, head, iframe, meter, noscript, object, s, script, select, style, textarea"))l(y);else if(y.tagName&&y.tagName.toLowerCase()==="img"&&y.src){let S=y.getAttribute("alt");if(S){let w=S.trim();if(w){let b=N3(y),m=void 0;n.push({combinedText:w,dir:m,lang:b,parentElement:y,textNodes:[]})}}}break;case Node.TEXT_NODE:r.length!==0&&o(g);break;default:break}f&&r.pop()}l(t);function u(d){if(!d.textNodes||!d.textNodes.length){(!d.combinedText||!d.combinedText.length)&&(d.combinedText="");return}d.combinedText=lN(d.textNodes,!0).replace(/[\r\n]/g," ");let f=d.parentElement;for(;f;){if(f.tagName){let g=f.tagName.toLowerCase();if(g==="pre"||g==="code"||g==="video"||g==="audio")break}f=f.parentElement}}for(let d of n)u(d);return n}findTtsQueueItemIndex(t,n,r,o,a){let l=0;for(let u of t){if(r&&u.textNodes){if(u.textNodes.includes(r))return l}else if(n===u.parentElement||u.parentElement!==n.ownerDocument.body&&u.parentElement!==a&&u.parentElement.contains(n)||n.contains(u.parentElement))return l;l++}return-1}restart(){window.speechSynthesis.speaking&&(window.speechSynthesis.cancel(),this.restartIndex=this.ttsQueueIndex,this.ttsPlayQueueIndexDebounced(this.restartIndex,this.ttsQueue))}startTTSSession(t,n){if(!Vo(t,n)){this.cancel();return}this.speaking=!0,this.ttsPlayQueueIndexDebounced(n,t)}ttsPlayQueueIndex(t,n){if(t<0){this.cancel();return}let r=Vo(n,t);if(!r){this.cancel();return}let o=Jo(r);if(!o){this.cancel();return}let a=new SpeechSynthesisUtterance(o);a.rate=this.tts.rate,a.pitch=this.tts.pitch,a.volume=this.tts.volume,Ke.default.log("this.tts.voice.lang",this.tts.voice.lang);var l=!0;this.tts.voice&&this.tts.voice.lang&&(l=this.tts.voice.lang.indexOf("-")!==-1,l===!1&&(this.tts.voice.lang=this.tts.voice.lang.replace("_","-"),l=!0)),Ke.default.log("initialVoiceHasHyphen",l),Ke.default.log("voices",this.voices);var u;l===!0?(u=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(S=>{var w=S.lang.replace("_","-");return w===this.tts.voice.lang&&S.name===this.tts.voice.name})[0]:void 0,u===void 0&&(u=this.tts.voice&&this.tts.voice.lang?this.voices.filter(S=>S.lang.replace("_","-")===this.tts.voice.lang)[0]:void 0)):(u=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(S=>S.lang===this.tts.voice.lang&&S.name===this.tts.voice.name)[0]:void 0,u===void 0&&(u=this.tts.voice&&this.tts.voice.lang?this.voices.filter(S=>S.lang===this.tts.voice.lang)[0]:void 0)),Ke.default.log("initialVoice",u);var d=this,f=d.delegate.publication.Metadata.Language[0].indexOf("-")!==-1;Ke.default.log("publicationVoiceHasHyphen",f);var g;f===!0?g=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(S=>{var w=S.lang.replace("_","-");return w.startsWith(d.delegate.publication.Metadata.Language[0])||w.endsWith(d.delegate.publication.Metadata.Language[0].toUpperCase())})[0]:void 0:g=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(S=>S.lang.startsWith(d.delegate.publication.Metadata.Language[0])||S.lang.endsWith(d.delegate.publication.Metadata.Language[0].toUpperCase()))[0]:void 0,Ke.default.log("publicationVoice",g);var y=navigator.language.indexOf("-")!==-1;Ke.default.log("defaultVoiceHasHyphen",y);var v;y===!0?v=this.voices.filter(S=>{var w=S.lang.replace("_","-");return w===navigator.language&&S.localService===!0})[0]:v=this.voices.filter(S=>{var w=S.lang;return w===navigator.language&&S.localService===!0})[0],v===void 0&&(v=this.voices.filter(S=>{var w=S.lang;return w.includes(navigator.language)&&S.localService===!0})[0]),Ke.default.log("defaultVoice",v),u?(Ke.default.log("initialVoice"),a.voice=u):g?(Ke.default.log("publicationVoice"),a.voice=g):v&&(Ke.default.log("defaultVoice"),a.voice=v),a.voice!==void 0&&a.voice!==null&&(a.lang=a.voice.lang,Ke.default.log("utterance.voice.lang",a.voice.lang),Ke.default.log("utterance.lang",a.lang)),Ke.default.log("navigator.language",navigator.language),a.onboundary=S=>{Ke.default.log(S.name),this.updateTTSInfo(r,S.charIndex,S.charLength,0,a.text)},setTimeout(()=>{window.speechSynthesis.speak(a),d.speaking||window.speechSynthesis.pause()},0),a.onend=function(){d.speaking&&d.ttsPlayQueueIndexDebounced(t+1,n)}}updateTTSInfo(t,n,r,o,a){if(!t)return;Ke.default.log(t,n,r,a);let l=a||Jo(t);if(n>=0&&a){let u=a.slice(0,n+1).search(/\S+$/),d=a.slice(n).search(/\s/),f=d<0?a.slice(u):a.slice(u,d+n),g=u+f.length;if(r===void 0){let y=a.substring(n).match(/^[a-z\d']*/i);y&&(r=y[0].length)}r===void 0&&(r=f.length),this.wrapHighlightWord(t,a,n+o,r,f,u,g)}return l}wrapHighlightWord(t,n,r,o,a,l,u){Ke.default.log(t),Ke.default.log(n),Ke.default.log(r,o,a,l,u),this._ttsQueueItemHighlightsWord&&(this.delegate.highlighter?.destroyHighlights(qe.ReadAloud),this._ttsQueueItemHighlightsWord=void 0);let d=t.item,f=r,g=0,y,v=-1,S,w=-1,b=f+o;for(let E of d.textNodes){if(!E.nodeValue&&E.nodeValue!=="")continue;let O=E.nodeValue.length;if(g+=O,y||f<g&&(y=E,v=O-(g-f)),y&&b<=g&&(S=E,w=O-(g-b)),S)break}if(y&&S){let O=function(T){try{let M=m.delegate.iframes[0].contentDocument;return M?Rn(T,M,no):""}catch(M){return Ke.default.log("uniqueCssSelector:"),Ke.default.error(M),""}},E=new Range;E.setStart(y,v),E.setEnd(S,w);var m=this;let _=Ri(E,O);if(!_)return;let A=this.delegate.highlighter?.createHighlight(this.delegate.iframes[0].contentWindow,{rangeInfo:_,cleanText:"",rawText:"",range:void 0},this.tts.color,!1,Le.Custom,{id:"tts",title:"",position:"right"},void 0,{defaultClass:this.tts.color},qe.ReadAloud,"R2_READALOUD_");if(A){this._ttsQueueItemHighlightsWord=A[0];let j=(A[1]?.firstChild?.getBoundingClientRect()).top-this.wrapper.scrollTop>window.innerHeight/2-65;this.delegate.view?.isScrollMode()&&this.tts.autoScroll&&!this.userScrolled&&this.scrollPartial&&j?A[1]?.firstChild?.scrollIntoView({block:"center",behavior:"smooth"}):this.delegate.view?.isPaginated()&&m.delegate.view?.snap(A[1]?.firstChild)}}}};function N3(i){let t=i;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let n=t.getAttribute("xml:lang");if(n||(n=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang")),n||(n=t.getAttribute("lang")),n)return n;t=t.parentNode}}function aN(i){let t=i;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let n=t.getAttribute("dir");if(n)return n;t=t.parentNode}}function lN(i,t){if(i&&i.length){let n="";for(let r of i)r.nodeValue&&(n+=t?r.nodeValue:uN(r.nodeValue));return n}return""}function cN(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function uN(i){return cN(i).replace(/\n/g," ").replace(/\s\s+/g," ")}function Vo(i,t){let n=-1,r=-1;for(let o of i)if(r++,n++,t===n)return{item:o,iArray:r,iGlobal:n,iSentence:-1}}function Jo(i){return i.item.combinedText}C();var cl=Je(Ed());var H3=Je(Qi());var j3=Je(Dt()),ag=class{constructor(t,n,r,o,a){this.currentChapterPopupResult=[];this.currentPopupHighlights=[];this.definitions=(0,H3.debounce)(async()=>{if(await this.highlighter.destroyHighlights(qe.Definition),this.properties.definitions)for(let t of this.properties.definitions)await this.define(t)},200);this.delegate=t,this.publication=n,this.properties=r,this.api=a,this.highlighter=o}static async create(t){let n=new this(t.delegate,t.publication,t,t.highlighter,t.api);return await n.start(),n}async stop(){j3.default.log("Definitions module stop")}async start(){this.delegate.definitionsModule=this,setTimeout(()=>{this.properties.hideLayer?this.delegate.hideLayer("definitions"):this.delegate.showLayer("definitions")},10)}async searchAndPaint(t,n){let r=this.publication.getAbsoluteHref(this.publication.readingOrder?this.publication.readingOrder[this.delegate.currentResource()??0].Href:""),o=this.publication.getTOCItem(r);o===void 0&&this.publication.readingOrder&&(o=this.publication.readingOrder[this.delegate.currentResource()??0]);let a=[];if(o)for(let l of t.terms){let u=t.terms.indexOf(l);o&&await Js(l,this.delegate.iframes[0].contentDocument,o.Href,o.Title,this.delegate.definitionsModule?.properties.fullWordSearch).then(d=>{let f;t.result===1?f=0:t.result===2&&(f=Math.floor(Math.random()*d.length-1)+1),d.forEach((g,y)=>{if(f===void 0||f===y){let v={rangeInfo:g.rangeInfo},S=this.createDefinitionHighlight(v,t);g.highlight=S,a.push(cl.omit(S,"definition")),this.currentChapterPopupResult.push(g),this.currentPopupHighlights.push(S)}}),u===t.terms.length-1&&n(a)})}}async define(t){await this.searchAndPaint(t,async n=>{this.api?.success&&(this.api?.success(cl.omit(t,"callbacks"),n),this.delegate.emit("definition.success",n),this.api?.visible&&n.forEach(r=>{let a=this.delegate.iframes[0].contentDocument?.querySelector(`#${r.id}`)?.querySelectorAll(`.${hn}`),l=new IntersectionObserver((u,d)=>{u.forEach(f=>{f.intersectionRatio===1&&(this.api?.visible(cl.omit(t,"callbacks"),cl.omit(r,"definition")),this.delegate.emit("definition.visible",t,r))})},{threshold:1});a&&a.length>0&&l.observe(a[0])}))})}async drawDefinitions(){setTimeout(async()=>{await this.definitions()},100)}async handleResize(){await this.drawDefinitions()}createDefinitionHighlight(t,n){try{let r=this.delegate.definitionsModule?.properties.color;De.isHexColor(r)&&(r=De.hexToRgbChannels(r));let o=`${t.rangeInfo.startContainerElementCssSelector}${t.rangeInfo.startContainerChildTextNodeIndex}${t.rangeInfo.startOffset}${t.rangeInfo.endContainerElementCssSelector}${t.rangeInfo.endContainerChildTextNodeIndex}${t.rangeInfo.endOffset}`,a=Tr.hash(o),l="R2_DEFINITION_"+a;this.highlighter.destroyHighlight(this.delegate.iframes[0].contentDocument,l);let u={color:r||Fo,id:l,pointerInteraction:!0,selectionInfo:t,marker:Le.Underline,type:qe.Definition};zt.push(u);let d=this.highlighter.createHighlightDom(this.delegate.iframes[0].contentWindow,u);return d&&(n.definition&&(d.dataset.definition=n.definition),d.dataset.order=String(n.order),u.definition=n,u.position=parseInt((d?.hasChildNodes()?d.childNodes[0]:d).style.top.replace("px",""))),u}catch(r){throw"Can't create definitions highlight: "+r}}async addDefinition(t){await this.define(t)}async clearDefinitions(){await this.highlighter.destroyHighlights(qe.Definition)}};C();var co=Je(Dt()),D3=.5,Gd=class{constructor(t,n,r,o){this.hasEventListener=!1;this.lines=[];this.index=0;this.isActive=!1;this.isDebug=!1;this.lineFocusContainer=document.getElementById("lineFocusContainer");this.readerContainer=document.getElementById("D2Reader-Container");this.lineFocusTopBlinder=document.getElementById("lineFocusTopBlinder");this.lineFocusBottomBlinder=document.getElementById("lineFocusBottomBlinder");this.wrapperHeight=void 0;this.delegate=t,this.properties=n,this.api=o,this.highlighter=r}static async create(t){let n=new this(t.delegate,t,t.highlighter,t.api);return await n.start(),n}async stop(){co.default.log("Definitions module stop"),this.hasEventListener=!1,Pe(document,"keydown",this.keydown.bind(this)),Pe(document,"keyup",this.keyup.bind(this)),Pe(this.delegate.iframes[0].contentDocument,"keydown",this.keydown.bind(this)),Pe(this.delegate.iframes[0].contentDocument,"keyup",this.keyup.bind(this))}async start(){this.delegate.lineFocusModule=this;let t=dt(document,"#iframe-wrapper");t.style.height.length>0&&(this.wrapperHeight=t.style.height,this.lineFocusContainer&&this.lineFocusContainer.style.height.length===0&&(this.lineFocusContainer.style.height=this.wrapperHeight),this.readerContainer&&this.readerContainer.style.height.length===0&&(this.readerContainer.style.height=this.wrapperHeight),this.readerContainer&&(this.readerContainer.style.overflow="hidden")),this.hasEventListener||(this.hasEventListener=!0,ne(document,"keydown",this.keydown.bind(this)),ne(document,"keyup",this.keyup.bind(this)),ne(this.delegate.iframes[0].contentDocument,"keydown",this.keydown.bind(this)),ne(this.delegate.iframes[0].contentDocument,"keyup",this.keyup.bind(this)))}keydown(t){if(t instanceof KeyboardEvent&&this.isActive)switch(t.key){case"ArrowUp":t.stopPropagation();break;case"ArrowDown":t.stopPropagation();break}}keyup(t){if(t instanceof KeyboardEvent&&this.isActive)switch(t.key){case"ArrowUp":this.lineUp();break;case"ArrowDown":this.lineDown();break}}handleResize(){this.isActive&&this.lineFocus()}async enableLineFocus(){this.isActive=!0,await this.delegate.settings.scroll(!0),this.lineFocus()}disableLineFocus(t=!0){this.isActive=!1;let n=dt(document,"#iframe-wrapper");this.wrapperHeight&&(n.style.height=this.wrapperHeight),t||(this.index=0);let r=this.delegate.iframes[0].contentDocument;Qt(r,"html").style.removeProperty("--USER__maxMediaHeight"),this.wrapperHeight=void 0,this.lineFocusContainer&&(this.lineFocusContainer.style.display="none");let a=document.getElementById("container-view-timeline");a&&a.style.removeProperty("display");let l=document.getElementById("divBefore");l&&l.remove();let u=document.getElementById("divAfter");u&&u.remove(),this.highlighter.destroyHighlights(qe.LineFocus)}lineFocus(){let t=dt(document,"#iframe-wrapper"),n=this.delegate.iframes[0].contentDocument,r=Qt(n,"html"),o=this.properties.maxHeight?Fr()*this.properties.maxHeight/100:Fr()/2;r.style.setProperty("--USER__maxMediaHeight",o+"px");function a(g,y){g.parentNode.insertBefore(y,g.nextSibling)}function l(g,y){g.parentNode.insertBefore(y,g)}let u=document.getElementById("container-view-timeline");u&&(u.style.display="none"),this.lineFocusContainer&&this.lineFocusContainer.style.removeProperty("display");let d=document.getElementById("divBefore");if(d)d.style.height=t.clientHeight/2+"px";else{let g=document.createElement("div");g.style.height=t.clientHeight/2+"px",g.id="divBefore",l(t,g)}let f=document.getElementById("divAfter");if(f)f.style.height=t.clientHeight/2+"px";else{let g=document.createElement("div");g.style.height=t.clientHeight/2+"px",g.id="divAfter",a(t,g)}if(this.lines=[],n){let v=function(){let O=Math.round,_=Math.random,A=255;return{blue:O(_()*A),green:O(_()*A),red:O(_()*A)}},S=function(O,_){let A=[];for(let T=0,M=0;T<O.length;T++)T>=_&&T%_==0&&M++,A[M]=A[M]||[],A[M].push(O[T]);return A},w=function(O,_){let A=Math.min(O.left,_.left),T=Math.max(O.right,_.right),M=Math.min(O.top,_.top),j=Math.max(O.bottom,_.bottom);return{bottom:j,height:j-M,left:A,right:T,top:M,width:T-A}},b=function(O){if(O.length>1){let _=w(O[0],O[1]);if(O.length>2){let A=w(_,O[2]);if(O.length>3){let T=w(A,O[3]);return O.length>4?w(T,O[4]):T}return A}return _}return O[0]},g=this.findRects(n.body);g=i0(g,!0),g=g.sort(function(O,_){return O.top-_.top});let y=[];g=g.filter(function(O){let _=O.top;return y.indexOf(_)===-1&&y.indexOf(_+1)===-1&&y.indexOf(_+2)===-1&&y.indexOf(_+3)===-1&&y.indexOf(_+4)===-1&&y.indexOf(_-1)===-1&&y.indexOf(_-2)===-1&&y.indexOf(_-3)===-1&&y.indexOf(_-4)===-1?(y.push(_),!0):!1}),this.highlighter.destroyHighlights(qe.LineFocus);let m=[];this.properties.lines&&this.properties.lines>1?S(g,this.properties.lines).forEach(_=>{m.push(b(_))}):m=g;let E=de(n,"#"+Re.R2_ID_LINEFOCUS_CONTAINER);if(E)for(let O of m){let _=document.createElement("div");_.setAttribute("class",hn);let A=v();if(De.isHexColor(A)&&(A=De.hexToRgbChannels(A)),this.isDebug){let he=`border-bottom: 1px solid rgba(${A.red}, ${A.green}, ${A.blue}, ${D3}) !important`;_.setAttribute("style",`mix-blend-mode: multiply; border-radius: 1px !important; background-color: rgba(${A.red}, ${A.green}, ${A.blue}, ${D3}) !important; ${he}`)}_.style.outline="none",_.tabIndex=0;let T=this.delegate.iframes[0].contentWindow.document,M=this.delegate.view.isPaginated();M?T.body.style.position="revert":T.body.style.position="relative";let j=T.body.getBoundingClientRect(),P=this.highlighter.getScrollingElement(T),q=M?-P.scrollLeft:j.left,U=M?-P.scrollTop:j.top,k=1,B=24,N,W,ye=this.delegate.iframes[0].contentWindow?.innerWidth,be=parseInt(getComputedStyle(n.documentElement).getPropertyValue("column-count")),fe=parseInt(getComputedStyle(n.documentElement).getPropertyValue("column-width")),re=parseInt(getComputedStyle(n.body).getPropertyValue("padding-left"));if(ye){let he=ye/(be||1);he<fe&&(he=ye),M||(he=parseInt(getComputedStyle(n.body).width.replace("px","")));let Ae=this.delegate.settings.fontSize/100,ue=20*Ae;Ae<=1&&(ue=-60);let Oe=0;Ae<=1&&(Oe=-60),N=Math.floor(O.left/he)*he+he-(B<40?40:B)+Oe,W=Math.floor(O.left/he)*he+(B<40?40:B)-ue;let Ce=parseInt(n.documentElement.style.getPropertyValue("--USER__pageMargins"));Ce>=2&&(W=W+re/be,N=N-re/be),M||(N=parseInt(getComputedStyle(n.body).width.replace("px","")),W=parseInt(getComputedStyle(n.body).width.replace("px",""))-he,Ce>=2&&(W=W+re/2,N=N-re/2))}_.style.setProperty("pointer-events","none"),_.style.position="absolute",_.scale=k,_.rect={height:O.height,left:O.left-q,top:O.top-U,width:O.width},_.style.width=`${_.rect.width*k}px`,_.style.height=`${_.rect.height*k}px`,_.style.left=`${_.rect.left*k}px`,_.style.top=`${_.rect.top*k}px`,this.lines.push(_),E.append(_)}setTimeout(()=>{this.currentLine()},100)}}currentLine(){let t=this.lines[this.index],n=t.style.top,o=parseInt(t.style.top.replace("px",""))+parseInt(t.style.height.replace("px",""))-parseInt(n.replace("px",""));if(this.lineFocusContainer){let l=(parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px",""))-o)/2;this.lineFocusTopBlinder&&(this.lineFocusTopBlinder.style.height=l+"px"),this.lineFocusBottomBlinder&&(this.lineFocusBottomBlinder.style.height=l+"px")}t.scrollIntoView({block:"center",behavior:"smooth"})}lineDown(){if(this.index<this.lines.length-1){this.index+=1,this.index>this.lines.length-1&&(this.index=this.lines.length-1);let t=this.lines[this.index],n=t.style.top,o=parseInt(t.style.top.replace("px",""))+parseInt(t.style.height.replace("px",""))-parseInt(n.replace("px",""));if(this.lineFocusContainer){let l=(parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px",""))-o)/2;this.lineFocusTopBlinder&&(this.lineFocusTopBlinder.style.height=l+"px"),this.lineFocusBottomBlinder&&(this.lineFocusBottomBlinder.style.height=l+"px")}t.scrollIntoView({block:"center",behavior:"smooth"})}}lineUp(){if(this.index>0){this.index-=1,this.index<0&&(this.index=0);let t=this.lines[this.index],n=t.style.top,o=parseInt(t.style.top.replace("px",""))+parseInt(t.style.height.replace("px",""))-parseInt(n.replace("px",""));if(this.lineFocusContainer){let l=(parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px",""))-o)/2;this.lineFocusTopBlinder&&(this.lineFocusTopBlinder.style.height=l+"px"),this.lineFocusBottomBlinder&&(this.lineFocusBottomBlinder.style.height=l+"px")}t.scrollIntoView({block:"center",behavior:"smooth"})}}almostEqual(t,n,r){return Math.abs(t-n)<=r}findRects(t){let n=this.findTextNodes(t),r=Array.from(t.getElementsByTagName("img")),o=[];return n.forEach(a=>{o.push(...this.measureTextNodes(a))}),r.forEach(a=>{o.push(...this.measureImageNodes(a))}),o}findTextNodes(t,n=[]){let r=t.firstChild;for(;r;)r.nodeType===1&&this.findTextNodes(r,n),r.nodeType===3&&r.textContent?.trim()&&(r.textContent.trim().length>1||r.parentElement?.tagName.toLowerCase()==="h1"||r.parentElement?.tagName.toLowerCase()==="h2"||r.parentElement?.tagName.toLowerCase()==="h3"||r.parentElement?.tagName.toLowerCase()==="h4"||r.parentElement?.tagName.toLowerCase()==="h5"||r.parentElement?.tagName.toLowerCase()==="h6")&&r.parentElement&&getComputedStyle(r.parentElement).verticalAlign==="baseline"&&n.push(r),r=r.nextSibling;return n}measureTextNodes(t){try{let n=document.createRange();n.selectNodeContents(t);let r=Array.from(n.getClientRects());return n.detach(),r}catch(n){co.default.log("measureTextNode "+n),co.default.log("measureTextNode "+t),co.default.log(`${t.textContent}`)}}measureImageNodes(t){try{let n=document.createRange();n.selectNode(t);let r=Array.from(n.getClientRects());return n.detach(),r}catch(n){co.default.log("measureTextNode "+n),co.default.log("measureTextNode "+t),co.default.log(`${t.textContent}`)}}};C();var Vd=Je(Dt()),lg=class{constructor(t,n,r,o,a){this.history=[];this.headerMenu=a,this.delegate=n,this.publication=r,this.properties=o,this.annotator=t}static async create(t){let n=new this(t.annotator,t.delegate,t.publication,t,t.headerMenu);return await n.start(),n}async stop(){Vd.default.log("Page Break module stop"),Pe(this.historyForwardAnchorElement,"click",this.handleHistoryForwardClick.bind(this)),Pe(this.historyBackAnchorElement,"click",this.handleHistoryBackClick.bind(this))}async handleResize(){await this.setup()}setup(){this.history.length>0&&(this.historyForwardAnchorElement&&this.historyCurrentIndex+1<this.history.length?this.historyForwardAnchorElement.className=this.historyForwardAnchorElement.className.replace(" disabled",""):this.historyForwardAnchorElement&&(this.historyForwardAnchorElement.removeAttribute("href"),this.historyForwardAnchorElement.className+=" disabled"),this.historyBackAnchorElement&&this.historyCurrentIndex>0?this.historyBackAnchorElement.className=this.historyBackAnchorElement.className.replace(" disabled",""):this.historyBackAnchorElement&&(this.historyBackAnchorElement.removeAttribute("href"),this.historyBackAnchorElement.className+=" disabled"))}async push(t,n){let r;if(n&&this.annotator){let o=await this.annotator.getLastReadingPosition();if(o&&o.locations.progression&&o.locations.progression>0&&(this.historyCurrentIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyCurrentIndex)),r=this.history[this.history.length-1],r&&r.href!==o.href||r===void 0)){let a=this.publication.getAbsoluteHref(o.href);Vd.default.log(o.href),Vd.default.log(a),o.href=a,this.history.push(o),this.historyCurrentIndex=this.history.length-1}this.historyCurrentIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyCurrentIndex)),r=this.history[this.history.length-1],(r&&r.href!==t.href||r===void 0)&&(this.history.push(t),this.historyCurrentIndex=this.history.length-1)}}async start(){this.delegate.historyModule=this,this.headerMenu&&(this.historyForwardAnchorElement=de(this.headerMenu,"#history-forward")),this.headerMenu&&(this.historyBackAnchorElement=de(this.headerMenu,"#history-back")),this.historyCurrentIndex=this.history.length-1,ne(this.historyForwardAnchorElement,"click",this.handleHistoryForwardClick.bind(this)),ne(this.historyBackAnchorElement,"click",this.handleHistoryBackClick.bind(this))}async handleHistoryForwardClick(t){this.history.length>0&&this.historyCurrentIndex+1<this.history.length&&(this.historyCurrentIndex=this.historyCurrentIndex+1,await this.delegate.navigate(this.history[this.historyCurrentIndex],!1)),t.preventDefault(),t.stopPropagation()}async handleHistoryBackClick(t){this.history.length>0&&this.historyCurrentIndex>0&&(this.historyCurrentIndex=this.historyCurrentIndex-1,await this.delegate.navigate(this.history[this.historyCurrentIndex],!1)),t.preventDefault(),t.stopPropagation()}};C();var F3=Je(Dt()),it;(function(r){r[r.Chicago=0]="Chicago",r[r.MLA=1]="MLA",r[r.APA=2]="APA"})(it||(it={}));var $3;(function(o){o.Author="Author",o.Editor="Editor",o.Translator="Translator",o.Compiler="Compiler"})($3||($3={}));var Jd=class{constructor(t,n,r,o,a){this.highlighter=r,this.delegate=t,this.properties=o,this.publication=n,this.api=a}static async create(t){let n=new this(t.delegate,t.publication,t.highlighter,t,t.api);return await n.start(),n}async stop(){F3.default.log("Timeline module stop")}copyToClipboard(t){let n=!0;if(window.clipboardData)window.clipboardData.setData("text/plain",t);else{let r=this.createElementForExecCommand(t);this.selectContent(r);try{window.netscape&&netscape.security&&netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"),n=document.execCommand("copy",!1)}catch(o){n=!1}document.body.removeChild(r)}n?this.api?.citationCreated("The text was copied to the clipboard!"):this.api?.citationFailed("Your browser doesn't allow clipboard access!")}createElementForExecCommand(t){let n=document.createElement("div");return n.style.position="absolute",n.style.left="-10000px",n.style.top="-10000px",n.innerHTML=t,document.body.appendChild(n),n.contentEditable=!0,n}selectContent(t){let n=document.createRange();n.selectNodeContents(t);let r=window.getSelection();r?.removeAllRanges(),r?.addRange(n)}async start(){this.delegate.citationModule=this;let t=this,n={id:"citationIcon",callback:function(r){let o=function(){let P="",q="",U="";return t.publication.Metadata.Author?.length>0&&0===0&&t.publication.Metadata.Author[0].Name&&t.publication.Metadata.Author[0].Name.length>0&&(U=U+t.publication.Metadata.Author[0].Name,q=q+t.publication.Metadata.Author[0].Name,P=P+t.publication.Metadata.Author[0].Name),U.length>0&&q.length>0&&P.length>0?[P+". ",q+". ",U+". "]:["","",""]},a=function(){let P="",q="",U="";return t.publication.Metadata.Publisher&&t.publication.Metadata.Publisher[0].Name&&(q=q+t.publication.Metadata.Publisher[0].Name+", ",P=P+t.publication.Metadata.Publisher[0].Name+", "),t.publication.Metadata.PublicationDate&&t.publication.Metadata.PublicationDate.getFullYear()>0&&(U=U+"("+t.publication.Metadata.PublicationDate.getFullYear()+")",q=q+t.publication.Metadata.PublicationDate.getFullYear(),P=P+t.publication.Metadata.PublicationDate.getFullYear()),U.length>0&&q.length>0&&P.length>0?[P+". ",q+". ",U+". "]:["","",""]},l=function(){return t.publication.Metadata.Title?[t.publication.Metadata.Title+". ",t.publication.Metadata.Title+". ",t.publication.Metadata.Title+". "]:["","",""]},u=function(){return["","",""]},d=function(){let P="",q="",U="";return t.publication.Metadata.Publisher&&t.publication.Metadata.Publisher[0].Name&&(q=q+t.publication.Metadata.Publisher[0].Name+", ",P=P+t.publication.Metadata.Publisher[0].Name+", ",U=U+t.publication.Metadata.Publisher[0].Name+", "),U.length>0&&q.length>0&&P.length>0?[P+". ",q+". ",U+". "]:["","",""]},f=function(){return["","",""]},g=function(){return["","",""]},y=function(){return["","",""]},v=function(){return t.properties.library?["Retrieved from "+t.properties.library+". ","Retrieved from "+t.properties.library+". ","Retrieved from "+t.properties.library+". "]:["","",""]},S=function(){return t.properties.appName?[t.properties.appName+". ",t.properties.appName+". ",t.properties.appName+". "]:["","",""]},w=function(){return t.properties.appLink?[t.properties.appLink+". ",t.properties.appLink+". ",t.properties.appLink+". "]:["","",""]},b=function(){return["","",""]},m=function(P,q){return P.length>q?P.substring(0,q)+"...":P},E=o()[0]+l()[0]+f()[0]+u()[0]+y()[0]+a()[0]+g()[0]+v()[0]+S()[0]+w()[0],O=o()[2]+a()[2]+l()[2]+u()[2]+d()[2]+f()[2]+g()[2]+y()[2]+v()[2]+S()[2]+w()[2],_=o()[1]+l()[1]+f()[1]+u()[1]+y()[1]+a()[1]+b()[1]+v()[1]+S()[1]+w()[1],A="\u201C"+m(r,t.properties.characters)+"\u201C<br><br><em>"+E+"</em>",T="\u201C"+m(r,t.properties.characters)+"\u201C<br><br><em>"+O+"</em>",M="\u201C"+m(r,t.properties.characters)+"\u201C<br><br><em>"+_+"</em>",j="";t.properties.styles?.includes(it[0])&&(j=j+"Chicago: <br>"+A+"<br><br>"),t.properties.styles?.includes(it[2])&&(j=j+"APA: <br>"+T+"<br><br>"),t.properties.styles?.includes(it[1])&&(j=j+"MLA: <br>"+M+"<br><br>"),t.copyToClipboard(j)}};this.highlighter?.addSelectionMenuItem(n)}};var Ko=class{constructor(t,n,r,o,a,l,u,d,f,g,y,v,S,w,b,m,E){this.settings=t;this.navigator=n;this.highlighter=r;this.bookmarkModule=o;this.annotationModule=a;this.ttsSettings=l;this.ttsModule=u;this.searchModule=d;this.definitionsModule=f;this.contentProtectionModule=g;this.timelineModule=y;this.mediaOverlaySettings=v;this.mediaOverlayModule=S;this.pageBreakModule=w;this.lineFocusModule=b;this.historyModule=m;this.citationModule=E;this.startReadAloud=()=>{this.navigator.startReadAloud()};this.stopReadAloud=()=>{this.navigator.stopReadAloud()};this.pauseReadAloud=()=>{this.navigator.pauseReadAloud()};this.resumeReadAloud=()=>{this.navigator.resumeReadAloud()};this.startReadAlong=()=>{this.navigator.startReadAlong()};this.stopReadAlong=()=>{this.navigator.stopReadAlong()};this.pauseReadAlong=()=>{this.navigator.pauseReadAlong()};this.resumeReadAlong=()=>{this.navigator.resumeReadAlong()};this.saveBookmark=async()=>await this.bookmarkModule?.saveBookmark()??!1;this.saveBookmarkPlus=async()=>this.bookmarkModule?.saveBookmarkPlus();this.deleteBookmark=async t=>await this.bookmarkModule?.deleteBookmark(t)??!1;this.deleteAnnotation=async t=>await this.annotationModule?.deleteAnnotation(t)??!1;this.addAnnotation=async t=>await this.annotationModule?.addAnnotation(t)??!1;this.hideAnnotationLayer=()=>this.annotationModule?.hideAnnotationLayer();this.showAnnotationLayer=()=>this.annotationModule?.showAnnotationLayer();this.hideLayer=t=>this.navigator?.hideLayer(t);this.showLayer=t=>this.navigator?.showLayer(t);this.activateMarker=(t,n)=>this.navigator?.activateMarker(t,n);this.deactivateMarker=()=>this.navigator?.deactivateMarker();this.clearDefinitions=async()=>{await this.definitionsModule?.clearDefinitions()};this.addDefinition=async t=>{await this.definitionsModule?.addDefinition(t)};this.search=async(t,n)=>await this.searchModule?.search(t,n)??[];this.goToSearchIndex=async(t,n,r)=>{this.navigator.rights.enableSearch&&await this.searchModule?.goToSearchIndex(t,n,r)};this.goToSearchID=async(t,n,r)=>{this.navigator.rights.enableSearch&&await this.searchModule?.goToSearchID(t,n,r)};this.clearSearch=async()=>{this.navigator.rights.enableSearch&&await this.searchModule?.clearSearch()};this.resetUserSettings=async()=>await this.settings.resetUserSettings();this.applyUserSettings=async t=>await this.settings.applyUserSettings(t);this.scroll=async t=>await this.settings.scroll(t);this.increase=async t=>{this.isTTSIncrementable(t)?this.navigator.rights.enableTTS&&await this.ttsSettings?.increase(t):this.isMOIncrementable(t)?this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.increase(t):await this.settings.increase(t)};this.decrease=async t=>{this.isTTSIncrementable(t)?this.navigator.rights.enableTTS&&await this.ttsSettings?.decrease(t):this.isMOIncrementable(t)?this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.decrease(t):await this.settings.decrease(t)};this.resetTTSSettings=()=>{this.navigator.rights.enableTTS&&this.ttsSettings?.resetTTSSettings()};this.applyTTSSettings=async t=>{this.navigator.rights.enableTTS&&await this.ttsSettings?.applyTTSSettings(t)};this.applyPreferredVoice=async t=>{this.navigator.rights.enableTTS&&await this.ttsSettings?.applyPreferredVoice(t)};this.resetMediaOverlaySettings=async()=>{this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.resetMediaOverlaySettings()};this.applyMediaOverlaySettings=async t=>{this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.applyMediaOverlaySettings(t)};this.goTo=async t=>{this.navigator.goTo(t)};this.goToPosition=async t=>this.navigator.goToPosition(t);this.nextResource=()=>{this.navigator.nextResource()};this.previousResource=()=>{this.navigator.previousResource()};this.nextPage=async()=>{this.navigator.nextPage()};this.previousPage=async()=>{this.navigator.previousPage()};this.snapToSelector=async t=>{this.navigator.snapToSelector(t)};this.applyAttributes=t=>{this.navigator.applyAttributes(t)};this.stop=()=>{document.body.onscroll=()=>{},this.navigator.stop(),this.settings.stop(),this.ttsSettings?.stop(),this.ttsModule?.stop(),this.bookmarkModule?.stop(),this.annotationModule?.stop(),this.searchModule?.stop(),this.definitionsModule?.stop(),this.contentProtectionModule?.stop(),this.timelineModule?.stop(),this.mediaOverlaySettings?.stop(),this.mediaOverlayModule?.stop(),this.pageBreakModule?.stop(),this.lineFocusModule?.stop()}}addEventListener(){this.navigator.addListener(arguments[0],arguments[1])}static async load(t){let n=t.rights??{autoGeneratePositions:!1,enableAnnotations:!1,enableBookmarks:!1,enableContentProtection:!1,enableDefinitions:!1,enableLineFocus:!1,enableMediaOverlays:!1,enablePageBreaks:!1,enableSearch:!1,enableTTS:!1,enableTimeline:!1,customKeyboardEvents:!1,enableHistory:!1,enableCitations:!1};n.enableContentProtection&&t.protection&&await jd.setupPreloadProtection(t.protection);let r=dt(document,"#D2Reader-Container"),o=de(document,"#headerMenu"),a=de(document,"#footerMenu"),l=t.url,u;t.publication?(u=Ts(t.publication,Ji),u.manifestUrl=new URL(l)):u=await Ji.fromUrl(l,t.requestConfig);let d=new Ys({prefix:u.manifestUrl,useLocalStorage:t.useLocalStorage??!1}),f=new Ys({prefix:"r2d2bc-reader",useLocalStorage:t.useLocalStorage??!1}),g=new Ys({prefix:"r2d2bc-layers",useLocalStorage:t.useLocalStorage??!1}),y=new lo({store:d});u.sample=t.sample,n=dN(n,u),n.autoGeneratePositions?await u.autoGeneratePositions(t.requestConfig):(t.services?.positions&&await u.fetchPositionsFromService(t.services?.positions.href,t.requestConfig),t.services?.weight&&await u.fetchWeightsFromService(t.services?.weight.href,t.requestConfig));let v=await ig.create({store:g}),S=await No.create({store:f,initialUserSettings:t.userSettings,headerMenu:o,api:t.api,injectables:(u.Metadata.Rendition?.Layout??"unknown")==="fixed"?t.injectablesFixed:t.injectables,layout:(u.Metadata.Rendition?.Layout??"unknown")==="fixed"?"fixed":"reflowable"}),w=await Ln.create({mainElement:r,headerMenu:o,footerMenu:a,publication:u,settings:S,annotator:y,initialLastReadingPosition:t.lastReadingPosition,api:t.api,rights:n,tts:t.tts,sample:t.sample,requestConfig:t.requestConfig,injectables:(u.Metadata.Rendition?.Layout??"unknown")==="fixed"?t.injectablesFixed??[]:t.injectables,attributes:t.attributes,services:t.services}),b=await De.create(Fe({delegate:w,layerSettings:v},t.highlighter)),m=n.enableBookmarks?await el.create(Fe({annotator:y,headerMenu:o,rights:n,publication:u,delegate:w,initialAnnotations:t.initialAnnotations},t.bookmarks)):void 0,E=n.enableAnnotations?await Qa.create(Fe({annotator:y,rights:n,publication:u,delegate:w,initialAnnotations:t.initialAnnotations,highlighter:b,headerMenu:o},t.annotations)):void 0,O=n.enableTTS,_=O?await ng.create({store:f,initialTTSSettings:t.tts,headerMenu:o}):void 0,A;O&&_&&(A=await sg.create(Fe({delegate:w,tts:_,headerMenu:o,rights:n,highlighter:b},t.tts)));let T=n.enableSearch?await tg.create(Fe({headerMenu:o,delegate:w,publication:u,highlighter:b},t.search)):void 0,M=n.enableDefinitions?await ag.create(Fe({delegate:w,publication:u,highlighter:b},t.define)):void 0,j=n.enableTimeline?await L0.create({publication:u,delegate:w}):void 0,P=n.enableContentProtection?await jd.create(Fe({delegate:w},t.protection)):void 0,q=n.enableMediaOverlays,U=q?await M0.create(Fe({store:f,initialMediaOverlaySettings:t.mediaOverlays,headerMenu:o},t.mediaOverlays)):void 0,k=q?await P0.create(Fe({publication:u,delegate:w,settings:U},t.mediaOverlays)):void 0,N=n.enablePageBreaks&&u.isReflowable?await og.create(Fe({publication:u,headerMenu:o,delegate:w},t.pagebreak)):void 0,W=n.enableLineFocus?await Gd.create(Fe({publication:u,delegate:w,highlighter:b},t.lineFocus)):void 0,ye=n.enableHistory?await lg.create({annotator:y,publication:u,delegate:w,headerMenu:o}):void 0,be=n.enableCitations?await Jd.create(Fe({publication:u,delegate:w,highlighter:b},t.citations)):void 0;return new Ko(S,w,b,m,E,_,A,T,M,P,j,U,k,N,W,ye,be)}get hasMediaOverlays(){return this.navigator.hasMediaOverlays}get tableOfContents(){return al(this.navigator.tableOfContents())??[]}get readingOrder(){return al(this.navigator.readingOrder())??[]}get bookmarks(){return this.bookmarkModule?.getBookmarks()??[]}get annotations(){return this.annotationModule?.getAnnotations()}get currentResource(){return this.navigator.currentResource()}get mostRecentNavigatedTocItem(){return this.navigator.mostRecentNavigatedTocItem()}get totalResources(){return this.navigator.totalResources()}get publicationLanguage(){return this.navigator.publication.Metadata.Language}get currentSettings(){return this.settings.currentSettings}isTTSIncrementable(t){return t==="pitch"||t==="rate"||t==="volume"}isMOIncrementable(t){return t==="mo_rate"||t==="mo_volume"}get currentLocator(){return this.navigator.currentLocator()}get positions(){return this.navigator.positions()}get atStart(){return this.navigator.atStart()}get atEnd(){return this.navigator.atEnd()}async applyLineFocusSettings(t){if(t.lines&&this.lineFocusModule){let n=this.lineFocusModule.properties.lines??1;this.lineFocusModule.index=this.lineFocusModule.index*n/parseInt(t.lines),this.lineFocusModule.index=Math.abs(parseInt(this.lineFocusModule.index.toFixed())),this.lineFocusModule.properties.lines=parseInt(t.lines),this.lineFocusModule.isActive&&await this.lineFocusModule.enableLineFocus()}t.debug!==void 0&&this.lineFocusModule&&(this.lineFocusModule.isDebug=t.debug,this.lineFocusModule.isActive&&await this.lineFocusModule.enableLineFocus())}lineUp(){this.lineFocusModule?.lineUp()}lineDown(){this.lineFocusModule?.lineDown()}async enableLineFocus(){await this.lineFocusModule?.enableLineFocus()}async lineFocus(t){t?await this.lineFocusModule?.enableLineFocus():this.lineFocusModule?.disableLineFocus()}disableLineFocus(){this.lineFocusModule?.disableLineFocus()}};function dN(i,t){return t.isFixedLayout&&(i.enableAnnotations=!1,i.enableSearch=!1,i.enableTTS=!1,i.enableDefinitions=!1,i.enablePageBreaks=!1,i.enableLineFocus=!1),t.sample?.isSampleRead&&(i.enableAnnotations=!1,i.enableSearch=!1,i.enableTTS=!1,i.enableDefinitions=!1,i.enableTimeline=!1,i.enableMediaOverlays=!1,i.enablePageBreaks=!1,i.enableLineFocus=!1),i}var fN=Ko,hN=Ko.load;return pN;})();
|
|
82
|
+
`;var zd=Je(Qi());C();var Ks=class{constructor(t){this.onBackwardSwipe=()=>{};this.onForwardSwipe=()=>{};this.setupEvents=t=>{let n=null,r=null,o=this;t&&(t.addEventListener("touchstart",function(a){a.changedTouches.length===1&&(n=a)},!1),t.addEventListener("touchend",function(a){if(a.changedTouches.length!==1||!n)return;let l=n.changedTouches[0],u=a.changedTouches[0];if(!l)return;let d=window.devicePixelRatio,f=(l.clientX-u.clientX)/d,g=(l.clientY-u.clientY)/d;if(Math.abs(f)<Ks.TAP_TOLERANCE&&Math.abs(g)<Ks.TAP_TOLERANCE){if(r){n=null,r=null;return}if(a.timeStamp-n.timeStamp>Ks.LONG_PRESS_MS){n=null,r=null;return}n=null,r=a;return}if(r=null,a.timeStamp-n.timeStamp>Ks.SLOW_SWIPE_MS){n=null;return}let y=(l.clientY-u.clientY)/(l.clientX-u.clientX);if(Math.abs(y)>.5){n=null;return}f<0?o.onBackwardSwipe(a):o.onForwardSwipe(a),n=null},!1))};this.navigator=t}},Go=Ks;Go.TAP_TOLERANCE=10,Go.LONG_PRESS_MS=500,Go.SLOW_SWIPE_MS=500;C();var $d=class{constructor(t){this.onBackwardSwipe=()=>{};this.onForwardSwipe=()=>{};this.setupEvents=t=>{t&&(this.focusin(t),this.keydown(t))};this.focusin=t=>{let n=this;t.addEventListener("focusin",function(r){n.navigator.view?.snap(r.target)},!0)};this.keydown=t=>{let n=this;this.navigator.rights.customKeyboardEvents||t.addEventListener("keydown",function(r){let o=r.target;if(/input|select|option|textarea/i.test(o.tagName)||!(o.ownerDocument||o).defaultView.getSelection().isCollapsed)return;switch(r.key){case"ArrowRight":n.onForwardSwipe(r);break;case"ArrowLeft":n.onBackwardSwipe(r);break}},!1)};this.navigator=t}};C();var A3=Je(Qi()),Ud=class{constructor(t){this.enforceSampleRead=(0,A3.debounce)(t=>{let n=Math.round(t.locations.totalProgression*100),r=!1;this.delegate.sample?.limit&&(r=n<=this.delegate.sample?.limit,this.delegate.view?.layout==="fixed"&&!r&&this.delegate.sample?.minimum&&t.locations.position<=this.delegate.sample?.minimum&&(r=!0));let o={37:1,38:0,39:1,40:1,32:1,33:1,34:1,35:1,36:1};function a(w){w.preventDefault()}function l(w){o[w.keyCode]&&!r&&a(w)}let u=!1,d=Object.defineProperty&&Object.defineProperty({},"passive",{get:function(){u=!0}});window.addEventListener("test",function(){},d);let f=u?{passive:!1}:!1;function g(w){w=w||window.event;let b=Math.max(-1,Math.min(1,w.wheelDelta||-w.detail));return b===-1&&!r&&w.preventDefault(),!1}let y;function v(w){w=w||window.event;let b=w.target||w.srcElement,m=w.touches[0].clientY;if(!(m>y)){if(m<y&&!r)return b.className.match(/\baltNav\b/)||(w.returnValue=!1,w.cancelable&&(w.cancelBubble=!0),w.preventDefault&&w.cancelable&&(w.preventDefault(),w.stopPropagation())),!1}return y=m,!1}function S(w){return w=w||window.event,y=w.touches[0].clientY,!1}window.addEventListener("mousewheel",g,f),window.addEventListener("DOMMouseScroll",g,f),window.addEventListener("keydown",l,f),window.addEventListener("touchmove",v,f),window.addEventListener("touchstart",S,f),r?(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=this.delegate.sample?.popup??""))},300);this.delegate=t}};var M3=Je(R3()),Yn=Je(Dt()),Ln=class extends M3.default{constructor(t,n=void 0,r=void 0,o,a,l,u,d,f,g,y,v){super();this.iframes=[];this.sideNavExpanded=!1;this.currentChapterLink={href:""};this.currentSpreadLinks={};this.rights={autoGeneratePositions:!1,enableAnnotations:!1,enableBookmarks:!1,enableContentProtection:!1,enableDefinitions:!1,enableLineFocus:!1,enableMediaOverlays:!1,enablePageBreaks:!1,enableSearch:!1,enableTTS:!1,enableTimeline:!1,customKeyboardEvents:!1,enableHistory:!1,enableCitations:!1};this.didInitKeyboardEventHandler=!1;this.onResize=()=>{clearTimeout(this.timeout),this.timeout=setTimeout(this.handleResize.bind(this),200)};this.reload=async()=>{let t;if(this.annotator&&(t=await this.annotator.getLastReadingPosition()),t){let n=this.publication.getAbsoluteHref(t.href);Yn.default.log(t.href),Yn.default.log(n),t.href=n,await this.navigate(t)}};this.savePosition=(0,zd.debounce)(()=>{this.annotator&&this.saveCurrentReadingPosition()},200);this.checkResourcePosition=(0,zd.debounce)(()=>{this.view?.atStart()&&this.view?.atEnd()?(this.api?.resourceFitsScreen&&this.api?.resourceFitsScreen(),this.emit("resource.fits")):this.view?.atEnd()?(this.api?.resourceAtEnd&&this.api?.resourceAtEnd(),this.emit("resource.end")):this.view?.atStart()&&(this.api?.resourceAtStart&&this.api?.resourceAtStart(),this.emit("resource.start"))},200);this.settings=t,this.annotator=n,this.view=t.view,this.view.attributes=f,this.view.delegate=this,this.eventHandler=new pd(this),this.touchEventHandler=new Go(this),this.keyboardEventHandler=new $d(this),this.initialLastReadingPosition=r,this.publication=o,this.api=a,this.rights=l??{autoGeneratePositions:!1,enableAnnotations:!1,enableBookmarks:!1,enableContentProtection:!1,enableDefinitions:!1,enableLineFocus:!1,enableMediaOverlays:!1,enablePageBreaks:!1,enableSearch:!1,enableTTS:!1,enableTimeline:!1,customKeyboardEvents:!1,enableHistory:!1,enableCitations:!1},this.tts=u,this.injectables=d,this.attributes=f||{margin:0},this.services=g,this.sample=y,this.requestConfig=v,this.sampleReadEventHandler=new Ud(this)}static async create(t){let n=new this(t.settings,t.annotator||void 0,t.initialLastReadingPosition||void 0,t.publication,t.api,t.rights,t.tts,t.injectables,t.attributes||{margin:0},t.services,t.sample,t.requestConfig);return await n.start(t.mainElement,t.headerMenu,t.footerMenu),new Promise(r=>r(n))}stop(){Yn.default.log("Iframe navigator stop"),Pe(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),Pe(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),Pe(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Pe(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),Pe(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),Pe(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),Pe(this.tryAgainButton,"click",this.tryAgain.bind(this)),Pe(this.goBackButton,"click",Ln.goBack.bind(this)),Pe(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),Pe(window,"resize",this.onResize),this.iframes.forEach(t=>{Pe(t,"resize",this.onResize)})}async start(t,n,r){this.headerMenu=n,this.mainElement=t;try{let S=dt(t,"main#iframe-wrapper");S.style.overflow="auto";let w=de(t,"main#iframe-wrapper iframe"),b=de(t,"#second");if(w&&this.iframes.push(w),b&&this.iframes.push(b),window.matchMedia("screen and (max-width: 600px)").matches&&(this.settings.columnCount=1),this.iframes.length===0){S.style.overflow="auto";let m=document.createElement("iframe");if(m.setAttribute("SCROLLING","no"),m.setAttribute("allowtransparency","true"),this.iframes.push(m),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]),S.appendChild(this.spreads)):(m.setAttribute("height","100%"),m.setAttribute("width","100%"),S.appendChild(this.iframes[0])),this.publication.isFixedLayout)if(this.settings.columnCount!==1&&!window.matchMedia("screen and (max-width: 600px)").matches){let E=document.createElement("div");this.spreads.appendChild(E);let O=document.createElement("iframe");O.setAttribute("SCROLLING","no"),O.setAttribute("allowtransparency","true"),O.style.opacity="1",O.style.border="none",O.style.overflow="hidden",this.iframes.push(O),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.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=(this.attributes?.iframePaddingTop??0)+"px"}if(this.publication.isFixedLayout){let m=S.clientHeight;var o=this.iframes[0].parentElement?.parentElement;o.style.height=m+40+"px"}else this.iframes.length===2&&this.iframes.pop();if(this.loadingMessage=de(t,"#reader-loading"),this.loadingMessage&&(this.loadingMessage.innerHTML=_3,this.loadingMessage.style.display="none"),this.errorMessage=de(t,"#reader-error"),this.errorMessage&&(this.errorMessage.innerHTML=T3,this.errorMessage.style.display="none"),this.tryAgainButton=de(t,"button[class=try-again]"),this.goBackButton=de(t,"button[class=go-back]"),this.infoTop=de(t,"div[class='info top']"),this.infoBottom=de(t,"div[class='info bottom']"),this.headerMenu&&(this.bookTitle=de(this.headerMenu,"#book-title")),this.infoBottom&&(this.chapterTitle=de(this.infoBottom,"span[class=chapter-title]")),this.infoBottom&&(this.chapterPosition=de(this.infoBottom,"span[class=chapter-position]")),this.infoBottom&&(this.remainingPositions=de(this.infoBottom,"span[class=remaining-positions]")),this.headerMenu&&(this.espandMenuIcon=de(this.headerMenu,"#expand-menu")),this.headerMenu&&(this.links=de(this.headerMenu,"ul.links.top")),this.headerMenu&&(this.linksTopLeft=de(this.headerMenu,"#nav-mobile-left")),this.headerMenu&&(this.tocView=de(this.headerMenu,"#container-view-toc")),this.headerMenu&&(this.landmarksView=de(this.headerMenu,"#container-view-landmarks")),this.headerMenu&&(this.landmarksSection=de(this.headerMenu,"#sidenav-section-landmarks")),this.headerMenu&&(this.pageListView=de(this.headerMenu,"#container-view-pagelist")),r&&(this.linksBottom=de(r,"ul.links.bottom")),r&&(this.linksMiddle=de(r,"ul.links.middle")),this.headerMenu&&(this.nextChapterAnchorElement=de(this.headerMenu,"a[rel=next]")),this.headerMenu&&(this.nextChapterBottomAnchorElement=de(t,"#next-chapter")),r&&(this.nextPageAnchorElement=de(r,"a[rel=next]")),this.headerMenu&&(this.previousChapterAnchorElement=de(this.headerMenu,"a[rel=prev]")),this.headerMenu&&(this.previousChapterTopAnchorElement=de(t,"#previous-chapter")),r&&(this.previousPageAnchorElement=de(r,"a[rel=prev]")),this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.newPosition=void 0,this.newElementId=void 0,this.isBeingStyled=!0,this.isLoading=!0,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),this.headerMenu){var a=de(this.headerMenu,"#menu-button-search"),l=de(this.headerMenu,"#menu-button-tts"),u=de(this.headerMenu,"#menu-button-bookmark"),d=de(this.headerMenu,"#menu-button-play"),f=de(this.headerMenu,"#menu-button-pause"),g=de(this.headerMenu,"#menu-button-mediaoverlay");if(!this.rights.enableBookmarks){u&&u.parentElement?.style.setProperty("display","none");var y=de(this.headerMenu,"#sidenav-section-bookmarks");y&&y.style.setProperty("display","none")}if(!this.rights.enableAnnotations){var v=de(this.headerMenu,"#sidenav-section-highlights");v&&v.style.setProperty("display","none")}this.rights.enableTTS||l&&l.parentElement?.style.setProperty("display","none"),this.rights.enableSearch||a&&a.parentElement?.style.setProperty("display","none"),a&&this.view?.delegate.publication.isFixedLayout&&a.parentElement?.style.setProperty("display","none"),this.hasMediaOverlays?(d&&d.parentElement?.style.removeProperty("display"),f&&f.parentElement?.style.removeProperty("display"),g&&g.parentElement?.style.removeProperty("display")):(d&&d.parentElement?.style.setProperty("display","none"),f&&f.parentElement?.style.setProperty("display","none"),g&&g.parentElement?.style.setProperty("display","none"))}else a&&a.parentElement?.style.setProperty("display","none"),l&&l.parentElement?.style.setProperty("display","none"),u&&u.parentElement?.style.setProperty("display","none");return this.setupEvents(),await this.loadManifest()}catch(S){return Yn.default.error(S),this.abortOnError(S),Promise.reject(S)}}setupEvents(){for(let t of this.iframes)ne(t,"load",this.handleIFrameLoad.bind(this));ne(this.previousChapterAnchorElement,"click",this.handlePreviousChapterClick.bind(this)),ne(this.nextChapterAnchorElement,"click",this.handleNextChapterClick.bind(this)),ne(this.previousChapterTopAnchorElement,"click",this.handlePreviousPageClick.bind(this)),ne(this.nextChapterBottomAnchorElement,"click",this.handleNextPageClick.bind(this)),ne(this.previousPageAnchorElement,"click",this.handlePreviousPageClick.bind(this)),ne(this.nextPageAnchorElement,"click",this.handleNextPageClick.bind(this)),ne(this.tryAgainButton,"click",this.tryAgain.bind(this)),ne(this.goBackButton,"click",Ln.goBack.bind(this)),ne(this.espandMenuIcon,"click",this.handleEditClick.bind(this)),ne(window,"resize",this.onResize);for(let t of this.iframes)ne(t,"resize",this.onResize)}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.keyboardEventHandler&&(this.keyboardEventHandler.onBackwardSwipe=this.handlePreviousChapterClick.bind(this),this.keyboardEventHandler.onForwardSwipe=this.handleNextChapterClick.bind(this)),this.touchEventHandler&&(this.touchEventHandler.onBackwardSwipe=this.handlePreviousPageClick.bind(this),this.touchEventHandler.onForwardSwipe=this.handleNextPageClick.bind(this))):(this.settings.isPaginated().then(t=>{if(t)this.view.height=Fr()-40-(this.attributes?.margin??0),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 n=(0,zd.debounce)(()=>{this.isScrolling=!1},200),r=dt(document,"#iframe-wrapper");r.onscroll=async()=>{this.isScrolling=!0,await 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(o=>{o||(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()),n()},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(async()=>{await this.highlighter?.prepareContainers(this.iframes[0].contentWindow),this.pageBreakModule!==void 0&&(await this.highlighter?.destroyHighlights(qe.PageBreak),await this.pageBreakModule.drawPageBreaks()),this.annotationModule!==void 0&&await this.annotationModule.drawHighlights(),this.bookmarkModule!==void 0&&await this.bookmarkModule.drawBookmarks(),this.rights.enableSearch&&this.searchModule!==void 0&&this.highlighter!==void 0&&(await this.highlighter.destroyHighlights(qe.Search),this.searchModule.drawSearch()),this.rights.enableDefinitions&&this.definitionsModule!==void 0&&this.highlighter!==void 0&&await this.definitionsModule.drawDefinitions()},200))}async loadManifest(){try{let t=(d,f,g=!1)=>{var y=document.createElement("ul");g&&(y=document.createElement("ol")),y.className="sidenav-toc";for(let v of f){let S=document.createElement("li"),w=document.createElement("a"),b=document.createElement("span");w.className="chapter-link",w.tabIndex=-1;let m="";v.Href?(m=this.publication.getAbsoluteHref(v.Href),w.href=m,w.innerHTML=v.Title||"",S.appendChild(w)):(b.innerHTML=v.Title||"",b.className="chapter-title",S.appendChild(b)),v.Children&&v.Children.length>0&&t(S,v.Children,!0),y.appendChild(S)}ne(y,"click",v=>{if(v.preventDefault(),v.stopPropagation(),v.target&&v.target.tagName.toLowerCase()==="a"){let S=v.target;if(S.className.indexOf("active")!==-1)this.hideView();else{let w={progression:0};if(S.href.indexOf("#")!==-1){let m=S.href.slice(S.href.indexOf("#")+1);m!==void 0&&(w={fragment:m})}let b={href:S.href,locations:w,type:S.type,title:S.title};this.hideView(),this.navigate(b)}}}),d.appendChild(y)},n=this.publication.tableOfContents,r=this.publication.landmarks,o=this.publication.pageList;this.tocView&&(n.length?t(this.tocView,n):this.tocView.parentElement?.parentElement?.removeChild(this.tocView.parentElement)),this.pageListView&&(o?.length?t(this.pageListView,o):this.pageListView.parentElement?.parentElement?.removeChild(this.pageListView.parentElement)),this.landmarksView&&(r?.length?t(this.landmarksView,r):this.landmarksSection.parentElement?.removeChild(this.landmarksSection));let a;this.annotator&&(a=await this.annotator.getLastReadingPosition());let l=this.publication.getStartLink(),u;if(l&&l.Href&&(u=this.publication.getAbsoluteHref(l.Href)),a){let d=this.publication.getAbsoluteHref(a.href);Yn.default.log(a.href),Yn.default.log(d),a.href=d,await this.navigate(a)}else if(u){let d={href:u,locations:{progression:0},created:new Date,title:l?.Title};await this.navigate(d)}return new Promise(d=>d())}catch(t){return Yn.default.error(t),this.abortOnError(t),new Promise((n,r)=>r(t)).catch(()=>{})}}async handleIFrameLoad(){this.errorMessage&&(this.errorMessage.style.display="none"),this.showLoadingMessageAfterDelay();try{let t=0;this.newPosition&&(t=this.newPosition.locations.progression),await this.handleResize(),this.updateBookView(),await this.settings.applyProperties();let n=this.currentChapterLink.href;if(n){let d=this.publication.getPreviousSpineItem(n);d&&d.Href&&(this.previousChapterLink={href:d.Href,title:d.Title,type:d.TypeLink})}this.previousChapterAnchorElement&&(this.previousChapterLink&&this.previousChapterLink.href?(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 r=this.publication.getNextSpineItem(n);r?this.nextChapterLink={href:r.Href,title:r.Title,type:r.TypeLink}:this.nextChapterLink=void 0,this.nextChapterAnchorElement&&(this.nextChapterLink&&this.nextChapterLink.href?(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.historyModule&&this.historyModule.setup(),this.currentTocUrl!==void 0?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(n),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let o=this.publication.getSpineItem(n);o!==void 0&&(this.currentChapterLink.title=o.Title,this.currentChapterLink.type=o.TypeLink);let a=this.publication.getTOCItem(n);this.currentTocUrl!==void 0&&(a=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&a!==void 0&&a.Title&&(this.currentChapterLink.title=a.Title),!this.currentChapterLink.type&&a!==void 0&&a.TypeLink&&(this.currentChapterLink.title=a.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),await this.injectInjectablesIntoIframeHead(),this.highlighter!==void 0&&await this.highlighter.initialize();let u=this.iframes[0].contentDocument?.body?.querySelector("details");if(u){let d=this;u.addEventListener("toggle",async f=>{await d.view?.setIframeHeight?.(this.iframes[0])})}if(this.rights.enableContentProtection&&this.contentProtectionModule!==void 0&&await this.contentProtectionModule.initialize(),this.eventHandler){for(let d of this.iframes)this.eventHandler.setupEvents(d.contentDocument),this.touchEventHandler.setupEvents(d.contentDocument),this.keyboardEventHandler.setupEvents(d.contentDocument);this.touchEventHandler.setupEvents(this.errorMessage),this.didInitKeyboardEventHandler||(this.keyboardEventHandler.keydown(document),this.didInitKeyboardEventHandler=!0)}if(this.view?.layout!=="fixed"&&this.view?.isScrollMode()&&(this.iframes[0].height="0",this.view?.setIframeHeight?.(this.iframes[0])),this.annotationModule!==void 0&&await this.annotationModule.initialize(),this.bookmarkModule!==void 0&&await this.bookmarkModule.initialize(),this.rights.enableTTS)for(let d of this.iframes){let f=d.contentDocument?.body;this.ttsModule!==void 0&&await this.ttsModule.initialize(f)}return this.timelineModule!==void 0&&await this.timelineModule.initialize(),this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&await this.mediaOverlayModule.initialize(),setTimeout(async()=>{if(this.newElementId){let d=this.iframes[0].contentDocument.getElementById(this.newElementId);this.view?.goToElement?.(d),this.newElementId=void 0}else if(this.newPosition&&this.newPosition.highlight){let d=this.newPosition.highlight?.selectionInfo.rangeInfo.startContainerElementCssSelector;d&&this.view?.goToCssSelector(d)}else t&&t>=0&&this.view?.goToProgression(t);if(this.newPosition=void 0,this.rights?.enableContentProtection&&this.contentProtectionModule!==void 0&&await this.contentProtectionModule.recalculate(10),this.hideLoadingMessage(),this.showIframeContents(),this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays){let d=this.currentLink();await this.mediaOverlayModule?.initializeResource(d)}await this.updatePositionInfo(),await this.view?.setSize(),setTimeout(()=>{this.mediaOverlayModule!==void 0&&(this.mediaOverlayModule.settings.resourceReady=!0)},300)},200),new Promise(d=>d())}catch(t){return Yn.default.error(t),this.abortOnError(t),Promise.reject(t)}}async injectInjectablesIntoIframeHead(){let t=[],n=r=>{let o=new Promise((a,l)=>{r.onload=()=>{a(!0)},r.onerror=u=>{let d=typeof u=="string"?u:`Injectable failed to load at: ${"href"in r?r.href:r.src}`;l(new Error(d))}});t.push(o)};for(let r of this.iframes){let o=r.contentDocument?.head;o&&(r.contentDocument.getElementsByTagName("base").length===0&&o.insertBefore(Ln.createBase(this.currentChapterLink.href),o.firstChild),this.injectables?.forEach(l=>{if(l.type==="style"){if(l.fontFamily){if(this.settings.initAddedFont(),!l.systemFont&&l.url){let u=Ln.createCssLink(l.url);o.appendChild(u),n(u)}}else if(l.r2before&&l.url){let u=Ln.createCssLink(l.url);o.insertBefore(u,o.firstChild),n(u)}else if(l.r2default&&l.url){let u=Ln.createCssLink(l.url);o.insertBefore(u,o.childNodes[1]),n(u)}else if(l.r2after&&l.url){l.appearance&&this.settings.initAddedAppearance();let u=Ln.createCssLink(l.url);o.appendChild(u),n(u)}else if(l.url){let u=Ln.createCssLink(l.url);o.appendChild(u),n(u)}}else if(l.type==="script"&&l.url){let u=Ln.createJavascriptLink(l.url,l.async??!1);o.appendChild(u),n(u)}}))}t.length!==0&&await Promise.all(t)}abortOnError(t){if(this.api?.onError){let n=t instanceof Error?t:typeof t=="string"?new Error(t):new Error("An unknown error occurred in the IFrameNavigator.");this.api.onError(n)}else this.errorMessage&&(this.errorMessage.style.display="block"),this.isLoading&&this.hideLoadingMessage()}tryAgain(){this.precessContentForIframe()}precessContentForIframe(){let t=this;var n=this.publication.getSpineIndex(this.currentChapterLink.href),r=(n??0)%2==1;this.showLoadingMessageAfterDelay();function o(d,f){let y=new DOMParser().parseFromString(d,"application/xhtml+xml");y.head&&y.getElementsByTagName("base").length===0&&y.head.insertBefore(Ln.createBase(f),y.head.firstChild);let v=y.documentElement.outerHTML,S=t.iframes[0].contentDocument;S&&(S.open(),S.write(v),S.close())}function a(d,f){let y=new DOMParser().parseFromString(d,"application/xhtml+xml");y.head&&y.getElementsByTagName("base").length===0&&y.head.insertBefore(Ln.createBase(f),y.head.firstChild);let v=y.documentElement.outerHTML,S=t.iframes[1].contentDocument;S&&(S.open(),S.write(v),S.close())}let l=new URL(this.currentChapterLink.href),u=window.location.protocol===l.protocol&&window.location.port===l.port&&window.location.hostname===l.hostname;if(this.api?.getContent)if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.api?.getContent(this.currentChapterLink.href).then(d=>{d===void 0?u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{o.call(this,f,this.currentChapterLink.href)}):o.call(this,d,this.currentChapterLink.href)}),this.iframes.length===2)if((n??0)<this.publication.readingOrder.length-1){let d=this.publication.getNextSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.right={href:f},this.api?.getContent(f).then(g=>{g===void 0?u?this.iframes[1].src=f:fetch(f,this.requestConfig).then(y=>y.text()).then(async y=>{a.call(this,y,f),this.currentSpreadLinks.right={href:f}}):a.call(this,g,f)})}}else this.iframes[1].src="about:blank"}else{if((n??0)>0){let d=this.publication.getPreviousSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.left={href:f},this.api?.getContent(f).then(g=>{g===void 0?u?this.iframes[0].src=f:fetch(f,this.requestConfig).then(y=>y.text()).then(async y=>{o.call(this,y,f)}):o.call(this,g,f)})}}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(d=>{d===void 0?u?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{a.call(this,f,this.currentChapterLink.href)}):a.call(this,d,this.currentChapterLink.href)}))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.api?.getContent(this.currentChapterLink.href).then(d=>{d===void 0?u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{o.call(this,f,this.currentChapterLink.href)}):o.call(this,d,this.currentChapterLink.href)});else this.api?.getContent(this.currentChapterLink.href).then(d=>{this.currentSpreadLinks.left={href:this.currentChapterLink.href},d===void 0?u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(f=>f.text()).then(async f=>{o.call(this,f,this.currentChapterLink.href)}):o.call(this,d,this.currentChapterLink.href)});else if(this.publication.isFixedLayout)if(this.settings.columnCount!==1)if(r){if(u){if(this.iframes[0].src=this.currentChapterLink.href,this.currentSpreadLinks.left={href:this.currentChapterLink.href},this.iframes.length===2)if((n??0)<this.publication.readingOrder.length-1){let d=this.publication.getNextSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.iframes[1].src=f,this.currentSpreadLinks.right={href:f}}}else this.iframes[1].src="about:blank"}else if(fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{o.call(this,d,this.currentChapterLink.href)}),this.iframes.length===2)if((n??0)<this.publication.readingOrder.length-1){let d=this.publication.getNextSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.right={href:f},fetch(f,this.requestConfig).then(g=>g.text()).then(async g=>{a.call(this,g,f)})}}else this.iframes[1].src="about:blank"}else{if((n??0)>0){let d=this.publication.getPreviousSpineItem(this.currentChapterLink.href);if(d){let f=this.publication.getAbsoluteHref(d.Href);this.currentSpreadLinks.left={href:f},u?(this.iframes[0].src=f,this.iframes.length===2&&(this.iframes[1].src=this.currentChapterLink.href)):(fetch(f,this.requestConfig).then(g=>g.text()).then(async g=>{o.call(this,g,f)}),this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},fetch(this.currentChapterLink.href,this.requestConfig).then(g=>g.text()).then(async g=>{a.call(this,g,this.currentChapterLink.href)})))}}else this.iframes[0].src="about:blank";this.iframes.length===2&&(this.currentSpreadLinks.right={href:this.currentChapterLink.href},u?this.iframes[1].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{a.call(this,d,this.currentChapterLink.href)}))}else this.currentSpreadLinks.left={href:this.currentChapterLink.href},u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{o.call(this,d,this.currentChapterLink.href)});else this.currentSpreadLinks.left={href:this.currentChapterLink.href},u?this.iframes[0].src=this.currentChapterLink.href:fetch(this.currentChapterLink.href,this.requestConfig).then(d=>d.text()).then(async d=>{o.call(this,d,this.currentChapterLink.href)});this.publication.isFixedLayout&&setTimeout(()=>{let d,f,g;if(n===0&&this.iframes?.length===2?g=this.iframes[1].contentDocument:g=this.iframes[0].contentDocument,g&&g.body&&(d=getComputedStyle(g.body).height,f=getComputedStyle(g.body).width,parseInt(d?.replace("px",""))===0||parseInt(f?.replace("px",""))===0)){let E=Qt(g,"head");if(E){let O=de(E,"meta[name=viewport]");if(O){var y=O.content,v=y.split(",").reduce((_,A)=>{var[T,M]=A.match(/[^\s;=]+/g);return _[T]=isNaN(Number(M))?M:+M,_},{});d=v.height+"px",f=v.width+"px"}}}var S=n===0&&this.iframes.length===2?this.iframes[1].parentElement?.parentElement:this.iframes[0].parentElement?.parentElement;if(S&&f){var w=(parseInt(getComputedStyle(S).width)-100)/(this.iframes.length===2?parseInt(f?.replace("px",""))*2+200:parseInt(f?.replace("px",""))),b=(parseInt(getComputedStyle(S).height)-100)/parseInt(d?.replace("px","")),m=Math.min(w,b);S.style.transform="scale("+m+")";for(let E of this.iframes)E.style.height=d,E.style.width=f,E.parentElement&&(E.parentElement.style.height=d)}},400)}static goBack(){window.history.back()}handleEditClick(t){var n=t.target;if(this.headerMenu){var r=de(document,".sidenav");n.className.indexOf(" active")===-1?(n.className+=" active",r.className+=" expanded",n.innerText="unfold_less",this.sideNavExpanded=!0,this.bookmarkModule?.showBookmarks(),this.annotationModule?.showHighlights()):(n.className=n.className.replace(" active",""),r.className=r.className.replace(" expanded",""),n.innerText="unfold_more",this.sideNavExpanded=!1,this.bookmarkModule?.showBookmarks(),this.annotationModule?.showHighlights())}t.preventDefault(),t.stopPropagation()}get hasMediaOverlays(){return this.publication.hasMediaOverlays}startReadAloud(){this.rights.enableTTS&&this.ttsModule.speakPlay()}startReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.startReadAloud()}stopReadAloud(){this.rights.enableTTS&&this.highlighter?.stopReadAloud()}stopReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.stopReadAloud()}pauseReadAloud(){this.rights.enableTTS&&(this.ttsModule.speakPause(),this.annotationModule!==void 0&&this.annotationModule.drawHighlights())}pauseReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.pauseReadAloud()}resumeReadAloud(){this.rights.enableTTS&&this.ttsModule.speakResume()}resumeReadAlong(){this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&this.mediaOverlayModule?.resumeReadAloud()}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 n=this.publication.getSpineItem(this.currentSpreadLinks.left.href),r=this.publication.getSpineItem(this.currentSpreadLinks.right.href);return[n,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()??!1}atEnd(){return this.view?.atEnd()??!1}previousPage(){this.handlePreviousPageClick(void 0)}nextPage(){this.handleNextPageClick(void 0)}previousResource(){this.handlePreviousChapterClick(void 0)}nextResource(){this.handleNextChapterClick(void 0)}goTo(t){let n=t.locations??{progression:0};if(t.href.indexOf("#")!==-1){let a=t.href.slice(t.href.indexOf("#")+1);a!==void 0&&(n=jt(Fe({},n),{fragment:a}))}let r=Fe({},t);r.locations=n;let o=this.publication.getAbsoluteHref(t.href);Yn.default.log(t.href),Yn.default.log(o),r.href=o,this.stopReadAloud(),this.navigate(r)}currentLocator(){let t;if(this.rights.autoGeneratePositions&&this.publication.positions||this.publication.positions){let n=this.publication.positionsByHref(this.publication.getRelativeHref(this.currentChapterLink.href)),r=Math.ceil((this.view?.getCurrentPosition()??0)*(n.length-1));t=n[r]}else{let n=this.publication.getTOCItem(this.currentChapterLink.href);n&&(this.currentTocUrl!==void 0&&(n=this.publication.getTOCItem(this.currentTocUrl)),n===void 0&&(n=this.publication.getTOCItemAbsolute(this.currentChapterLink.href)),n&&(t={href:n.Href,type:this.currentChapterLink.type,title:this.currentChapterLink.title,locations:{}}))}return t&&(t.locations.progression=this.view?.getCurrentPosition(),t.displayInfo={resourceScreenIndex:Math.round(this.view?.getCurrentPage()??0),resourceScreenCount:Math.round(this.view?.getPageCount()??0)}),t}positions(){return this.publication.positions?this.publication.positions:[]}goToPosition(t){if(this.publication.positions){let n=this.publication.positions.filter(r=>r.locations.position===parseInt(String(t)))[0];this.goTo(n)}}async goToPage(t){this.pageBreakModule!==void 0&&await this.pageBreakModule.goToPageNumber(t)}snapToSelector(t){let n=this.iframes[0].contentDocument;if(n){Yn.default.log(t);let r=n.querySelectorAll(t);r.length>0&&this.view?.snap(r[0])}}applyAttributes(t){this.attributes=t,this.view.attributes=t,this.handleResize()}handlePreviousPageClick(t){this.stopReadAloud(),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){let n=!0;if(this.sample?.isSampleRead&&this.publication.positions){let r=this.currentLocator(),o=Math.round((r.locations.totalProgression??0)*100);this.sample?.limit&&(n=o<=this.sample?.limit,this.view?.layout==="fixed"&&((!n&&this.sample?.minimum&&r.locations.position)??0<=(this.sample?.minimum??0))&&(n=!0))}(n&&this.sample?.isSampleRead&&this.publication.positions||!this.sample?.isSampleRead||!this.publication.positions)&&(this.stopReadAloud(),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()))),!n&&this.sample?.isSampleRead&&this.publication.positions&&t&&(t.preventDefault(),t.stopPropagation())}handleClickThrough(t){}handleInternalLink(t){let n=t.target,r={progression:0},o=n;if(o.href.indexOf("#")!==-1){let l=o.href.slice(o.href.indexOf("#")+1);l!==void 0&&(r={fragment:l})}let a={href:o.href,locations:r,type:o.type,title:o.title};t.preventDefault(),t.stopPropagation(),this.stopReadAloud(),this.navigate(a)}handleNumberOfIframes(){if(this.publication.isFixedLayout){if(this.settings.columnCount!==1&&!window.matchMedia("screen and (max-width: 600px)").matches){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 n=document.createElement("div");this.spreads.appendChild(n),n.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",n.style.clipPath="polygon(0% -20%, 100% -20%, 120% 100%, 0% 120%)",n.style.boxShadow="0 0 8px 2px #ccc"}else this.iframes.length===2&&(this.iframes.pop(),this.spreads.lastChild&&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()}}async handleResize(){if(this.isScrolling)return;if(this.publication.isFixedLayout){var t=this.publication.getSpineIndex(this.currentChapterLink.href);let f=Fr()-40-(this.attributes?.margin??0);var n=t===0&&this.iframes.length===2?this.iframes[1].parentElement?.parentElement:this.iframes[0].parentElement?.parentElement;if(n){n.style.height=f+40+"px";let g,y,v;t===0&&this.iframes?.length===2?v=this.iframes[1].contentDocument:v=this.iframes[0].contentDocument,v&&v.body&&(g=getComputedStyle(v.body).height,y=getComputedStyle(v.body).width);let S=Qt(v,"head");if(S){let w=de(S,"meta[name=viewport]");if(w){var r=w.content,o=r.split(",").reduce((b,m)=>{var[E,O]=m.match(/[^\s;=]+/g);return b[E]=isNaN(Number(O))?O:+O,b},{});(parseInt(o.height)!==0||parseInt(o.width)!==0)&&(g=o.height+"px",y=o.width+"px")}}var a=(parseInt(getComputedStyle(n).width)-100)/(this.iframes.length===2?parseInt(y?.replace("px",""))*2+200:parseInt(y?.replace("px",""))),l=(parseInt(getComputedStyle(n).height)-100)/parseInt(g?.replace("px","")),u=Math.min(a,l);n.style.transform="scale("+u+")";for(let w of this.iframes)w.style.height=g,w.style.width=y,w.parentElement&&(w.parentElement.style.height=g)}}let d=this.view?.getCurrentPosition();await 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(f=>{f?(this.view.height=Fr()-40-(this.attributes?.margin??0),this.infoBottom&&this.infoBottom.style.removeProperty("display")):this.infoBottom&&(this.infoBottom.style.display="none")}),setTimeout(()=>{this.view?.layout!=="fixed"&&this.view?.isScrollMode()&&this.view?.setIframeHeight?.(this.iframes[0])},100),setTimeout(async()=>{d&&this.view?.goToProgression(d),await this.updatePositionInfo(!1),this.annotationModule!==void 0&&await this.annotationModule.handleResize(),this.bookmarkModule!==void 0&&await this.bookmarkModule.handleResize(),this.searchModule!==void 0&&await this.searchModule.handleResize(),this.definitionsModule!==void 0&&await this.definitionsModule.handleResize(),this.pageBreakModule!==void 0&&await this.pageBreakModule.handleResize(),this.contentProtectionModule!==void 0&&this.contentProtectionModule.handleResize(),this.lineFocusModule!==void 0&&this.lineFocusModule.handleResize(),this.historyModule!==void 0&&this.historyModule.handleResize()},150)}updatePositionInfo(t=!0){if(this.view?.layout==="fixed")this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");else if(this.view?.isPaginated()){let n=this.currentLocator();if(n){let r=n.displayInfo.resourceScreenIndex,o=n.displayInfo.resourceScreenCount;this.chapterPosition&&(this.chapterPosition.innerHTML="Page "+r+" of "+o)}}else this.chapterPosition&&(this.chapterPosition.innerHTML=""),this.remainingPositions&&(this.remainingPositions.innerHTML="");t&&this.savePosition()}handlePreviousChapterClick(t){if(this.view?.layout==="fixed"&&this.settings.columnCount!==1){let n=this.publication.getSpineIndex(this.currentChapterLink.href)??0;n=n-2,n<0&&(n=0);let r=this.publication.readingOrder[n],o={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(),this.navigate(o)}else if(this.previousChapterLink){let n={href:this.publication.getAbsoluteHref(this.previousChapterLink.href),locations:{progression:1},type:this.previousChapterLink.type,title:this.previousChapterLink.title};this.stopReadAloud(),this.navigate(n)}t&&(t.preventDefault(),t.stopPropagation())}handleNextChapterClick(t){if(this.view?.layout==="fixed"&&this.settings.columnCount!==1){let n=this.publication.getSpineIndex(this.currentChapterLink.href)??0;n=n+2,n>=this.publication.readingOrder.length-1&&(n=this.publication.readingOrder.length-1);let r=this.publication.readingOrder[n],o={href:this.publication.getAbsoluteHref(r.Href),locations:{progression:0},type:r.TypeLink,title:r.Title};this.stopReadAloud(),this.navigate(o)}else if(this.nextChapterLink){let n={href:this.publication.getAbsoluteHref(this.nextChapterLink.href),locations:{progression:0},type:this.nextChapterLink.type,title:this.nextChapterLink.title};this.stopReadAloud(),this.navigate(n)}t&&(t.preventDefault(),t.stopPropagation())}hideView(){this.view?.layout!=="fixed"&&this.view?.isScrollMode()&&(document.body.style.overflow="auto")}setActiveTOCItem(t){if(this.tocView){let n=Array.prototype.slice.call(this.tocView.querySelectorAll("li > a"));for(let o of n)o.className=o.className.replace(" active","");let r=this.tocView.querySelector('li > a[href^="'+t+'"]');r&&(r.className+=" active")}}async navigate(t,n=!0){if(this.historyModule&&this.historyModule.push(t,n),this.publication.getTOCItem(t.href)){var o=!1;if(t.href.indexOf("#")!==-1){let a=t.href.slice(0,t.href.indexOf("#"));a===this.currentChapterLink.href&&(o=!0),this.currentChapterLink.href=a,this.currentChapterLink.type=t.type,this.currentChapterLink.title=t.title}else t.href===this.currentChapterLink.href&&(o=!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(o){if(t.href.indexOf("#")!==-1){let g=t.href.slice(t.href.indexOf("#")+1);t.locations={fragment:g}}if(this.newPosition=t,this.currentTOCRawLink=t.href,t.locations.fragment===void 0?this.currentTocUrl=void 0:(this.newElementId=t.locations.fragment,this.currentTocUrl=this.currentChapterLink.href+"#"+this.newElementId),this.newElementId){for(let g of this.iframes){let y=g.contentDocument.getElementById(this.newElementId);this.view?.goToElement?.(y)}this.newElementId=void 0}else if(t.highlight){let g=t.highlight?.selectionInfo.rangeInfo.startContainerElementCssSelector;g&&this.view?.goToCssSelector(g)}else this.view?.goToProgression(t.locations.progression??0);let a=this.currentChapterLink.href,l=this.publication.getPreviousSpineItem(a);l&&l.Href&&(this.previousChapterLink={href:l.Href,type:l.TypeLink,title:l.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 u=this.publication.getNextSpineItem(a);u?this.nextChapterLink={href:u.Href,type:u.TypeLink,title:u.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!==void 0?this.setActiveTOCItem(this.currentTocUrl):this.setActiveTOCItem(a),this.publication.Metadata.Title&&this.bookTitle&&(this.bookTitle.innerHTML=this.publication.Metadata.Title.toString());let d=this.publication.getSpineItem(a);d!==void 0&&(this.currentChapterLink.title=d.Title,this.currentChapterLink.type=d.TypeLink);let f=this.publication.getTOCItem(a);this.currentTocUrl!==void 0&&(f=this.publication.getTOCItem(this.currentTocUrl)),!this.currentChapterLink.title&&f!==void 0&&f.Title&&(this.currentChapterLink.title=f.Title),!this.currentChapterLink.type&&f!==void 0&&f.TypeLink&&(this.currentChapterLink.title=f.Title),this.currentChapterLink.title?this.chapterTitle&&(this.chapterTitle.innerHTML="("+this.currentChapterLink.title+")"):this.chapterTitle&&(this.chapterTitle.innerHTML="(Current Chapter)"),await this.updatePositionInfo()}else this.lineFocusModule!==void 0&&this.lineFocusModule.disableLineFocus(!1),this.searchModule!==void 0&&this.searchModule.clearSearch(),t.locations.fragment===void 0?this.currentTocUrl=void 0:(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(),this.rights.enableContentProtection&&this.contentProtectionModule!==void 0&&await this.contentProtectionModule.initializeResource(),this.rights.enableMediaOverlays&&this.mediaOverlayModule!==void 0&&this.hasMediaOverlays&&await this.mediaOverlayModule.initializeResource(this.currentLink()),this.rights.enableContentProtection&&this.contentProtectionModule!==void 0&&this.contentProtectionModule.recalculate(300),this.annotationModule!==void 0&&(await this.annotationModule.drawHighlights(),await this.annotationModule.showHighlights()),this.bookmarkModule!==void 0&&(await this.bookmarkModule.drawBookmarks(),await this.bookmarkModule.showBookmarks()),this.pageBreakModule!==void 0&&(await this.highlighter?.destroyHighlights(qe.PageBreak),await this.pageBreakModule.drawPageBreaks()),this.rights.enableSearch&&this.searchModule!==void 0&&this.highlighter!==void 0&&(await this.highlighter.destroyHighlights(qe.Search),this.searchModule.drawSearch()),this.rights.enableDefinitions&&this.definitionsModule!==void 0&&this.highlighter!==void 0&&this.definitionsModule.drawDefinitions(),this.view?.layout==="fixed"?(this.nextChapterBottomAnchorElement&&(this.nextChapterBottomAnchorElement.style.display="none"),this.previousChapterTopAnchorElement&&(this.previousChapterTopAnchorElement.style.display="none"),this.api?.resourceFitsScreen&&this.api?.resourceFitsScreen(),this.emit("resource.fits")):this.settings.isPaginated().then(a=>{a||(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 a=this.publication.getStartLink(),l;if(a&&a.Href&&(l=this.publication.getAbsoluteHref(a.Href),l)){let u={href:l,locations:{progression:0},created:new Date,title:a.Title};await this.navigate(u)}}}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")),this.mediaOverlayModule!==void 0&&(this.mediaOverlayModule.settings.resourceReady=!1)}hideIframeContents(){this.isBeingStyled=!0,this.iframes.forEach(t=>{t.style.opacity="0",t.style.border="none",t.style.overflow="hidden"})}hideLoadingMessage(){setTimeout(()=>{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()?(this.api?.resourceFitsScreen&&this.api?.resourceFitsScreen(),this.emit("resource.fits")):this.view?.atEnd()?(this.api?.resourceAtEnd&&this.api?.resourceAtEnd(),this.emit("resource.end")):this.view?.atStart()&&(this.api?.resourceAtStart&&this.api?.resourceAtStart(),this.emit("resource.start"))),this.api?.resourceReady&&this.api?.resourceReady(),this.emit("resource.ready")},150)}saveCurrentReadingPosition(){if(this.annotator){var t=this.publication.getTOCItem(this.currentChapterLink.href);this.currentTocUrl!==void 0&&(t=this.publication.getTOCItem(this.currentTocUrl)),t===void 0&&(t=this.publication.getTOCItemAbsolute(this.currentChapterLink.href));let n={progression:this.view?.getCurrentPosition()};if(t){if(t.Href.indexOf("#")!==-1){let o=t.Href.slice(t.Href.indexOf("#")+1);o!==void 0&&(n={progression:this.view?.getCurrentPosition(),fragment:o})}let r;if(this.rights.autoGeneratePositions&&this.publication.positions||this.publication.positions){let o=this.publication.positionsByHref(this.publication.getRelativeHref(t.Href));if(o.length>0){let a=Math.ceil((n.progression??0)*(o.length-1)),l=o[a];l&&(l.locations.fragment=n.fragment,r=jt(Fe({},l),{href:t.Href,created:new Date,title:this.currentChapterLink.title}))}}else r={href:t.Href,locations:n,created:new Date,type:this.currentChapterLink.type,title:this.currentChapterLink.title};r&&(this.sample?.isSampleRead&&this.publication.positions&&this.sampleReadEventHandler?.enforceSampleRead(r),this.api?.updateCurrentLocation?this.api?.updateCurrentLocation(r).then(async o=>(Yn.default.log("api updated current location",r),this.annotator?.saveLastReadingPosition(r))):(Yn.default.log("save last reading position",r),this.annotator.saveLastReadingPosition(r)))}}}static createBase(t){let n=document.createElement("base");return n.target="_self",n.href=t,n}static createCssLink(t){let n=document.createElement("link");return n.rel="stylesheet",n.type="text/css",n.href=t,n}static createJavascriptLink(t,n){let r=document.createElement("script");return r.type="text/javascript",r.src=t,r.async=n,r}activateMarker(t,n){this.annotationModule!==void 0&&(this.annotationModule.activeAnnotationMarkerId===void 0||this.annotationModule.activeAnnotationMarkerId!==t?(this.annotationModule.activeAnnotationMarkerId=t,this.annotationModule.activeAnnotationMarkerPosition=n,this.highlighter&&(this.highlighter.activeAnnotationMarkerId=t)):this.deactivateMarker())}deactivateMarker(){this.annotationModule!==void 0&&(this.annotationModule.activeAnnotationMarkerId=void 0,this.annotationModule.activeAnnotationMarkerPosition=void 0,this.highlighter&&(this.highlighter.activeAnnotationMarkerId=void 0))}showLayer(t){let n="#",r=new xa("layer-on","layer-off",!0,t,"layer-"+t);switch(t){case"annotations":case"highlights":n+=Re.R2_ID_HIGHLIGHTS_CONTAINER,r.name=Re.R2_ID_HIGHLIGHTS_CONTAINER;break;case"readaloud":n+=Re.R2_ID_READALOUD_CONTAINER,r.name=Re.R2_ID_READALOUD_CONTAINER;break;case"pagebreak":n+=Re.R2_ID_PAGEBREAK_CONTAINER,r.name=Re.R2_ID_PAGEBREAK_CONTAINER;break;case"search":n+=Re.R2_ID_SEARCH_CONTAINER,r.name=Re.R2_ID_SEARCH_CONTAINER;break;case"definitions":n+=Re.R2_ID_DEFINITIONS_CONTAINER,r.name=Re.R2_ID_DEFINITIONS_CONTAINER;break}this.highlighter?.layerSettings.saveProperty(r);let o=this.iframes[0].contentDocument;if(o){let a=de(o,n);a&&(a.style.display="block")}}hideLayer(t){let n="#",r=new xa("layer-on","layer-off",!1,t,"layer-"+t);switch(t){case"annotations":case"highlights":n+=Re.R2_ID_HIGHLIGHTS_CONTAINER,r.name=Re.R2_ID_HIGHLIGHTS_CONTAINER;break;case"readaloud":n+=Re.R2_ID_READALOUD_CONTAINER,r.name=Re.R2_ID_READALOUD_CONTAINER;break;case"pagebreak":n+=Re.R2_ID_PAGEBREAK_CONTAINER,r.name=Re.R2_ID_PAGEBREAK_CONTAINER;break;case"search":n+=Re.R2_ID_SEARCH_CONTAINER,r.name=Re.R2_ID_SEARCH_CONTAINER;break;case"definitions":n+=Re.R2_ID_DEFINITIONS_CONTAINER,r.name=Re.R2_ID_DEFINITIONS_CONTAINER;break}this.highlighter?.layerSettings.saveProperty(r);let o=this.iframes[0].contentDocument;if(o){let a=de(o,n);a&&(a.style.display="none")}}};C();var yt=class{constructor(t){this.store=t.store}getLastReadingPosition(){let t=this.store.get(yt.LAST_READING_POSITION);return t?JSON.parse(t):null}initLastReadingPosition(t){if(typeof t=="string")this.store.set(yt.LAST_READING_POSITION,t);else{let n=JSON.stringify(t);this.store.set(yt.LAST_READING_POSITION,n)}}saveLastReadingPosition(t){if(typeof t=="string")this.store.set(yt.LAST_READING_POSITION,t);else{let n=JSON.stringify(t);this.store.set(yt.LAST_READING_POSITION,n)}}initBookmarks(t){if(typeof t=="string"){let n=JSON.parse(t);this.store.set(yt.BOOKMARKS,JSON.stringify(n))}else this.store.set(yt.BOOKMARKS,JSON.stringify(t));return t}saveBookmark(t){let n=this.store.get(yt.BOOKMARKS);if(n){let r=JSON.parse(n);r.push(t),this.store.set(yt.BOOKMARKS,JSON.stringify(r))}else{let r=[];r.push(t),this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return t}locatorExists(t,n){let r;switch(n){case fr.Bookmark:r=yt.BOOKMARKS;break}let o=this.store.get(r);return o&&JSON.parse(o).filter(u=>u.href===t.href&&u.locations.progression===t.locations.progression).length>0?t:null}deleteBookmark(t){let n=this.store.get(yt.BOOKMARKS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.id!==t.id),this.store.set(yt.BOOKMARKS,JSON.stringify(r))}return t}getBookmarks(t){let n=this.store.get(yt.BOOKMARKS);if(n){let r=JSON.parse(n);if(t){let o=r.filter(a=>a.href===t);return o=o.sort((a,l)=>{if(a.locations.progression&&l.locations.progression)return a.locations.progression-l.locations.progression}),o}return r=r.sort((o,a)=>{if(o.locations.progression&&a.locations.progression)return o.locations.progression-a.locations.progression}),r}return[]}initAnnotations(t){let n;typeof t=="string"?n=JSON.parse(t):n=t;let r=[];return n.forEach(o=>{let a=`${o.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector}${o.highlight.selectionInfo.rangeInfo.startContainerChildTextNodeIndex}${o.highlight.selectionInfo.rangeInfo.startOffset}${o.highlight.selectionInfo.rangeInfo.endContainerElementCssSelector}${o.highlight.selectionInfo.rangeInfo.endContainerChildTextNodeIndex}${o.highlight.selectionInfo.rangeInfo.endOffset}`,l=Tr.hash(a);o.highlight.id="R2_HIGHLIGHT_"+l;let u;o.highlight.color?u=o.highlight.color:o.color&&(u=o.color),De.isHexColor(u)&&(u=De.hexToRgbString(u)),o.highlight.color=u,o.highlight.pointerInteraction=!0,o.highlight.selectionInfo.cleanText=o.highlight.selectionInfo.rawText.trim().replace(/\n/g," ").replace(/\s\s+/g," "),r.push(o)}),this.store.set(yt.ANNOTATIONS,JSON.stringify(r)),r}saveTemporarySelectionInfo(t){this.store.set(yt.SELECTIONINFO,JSON.stringify(t))}getTemporarySelectionInfo(t){let n=this.store.get(yt.SELECTIONINFO);if(n){let r=JSON.parse(n);return r.range=vd(t,r.rangeInfo),r}return[]}deleteTemporarySelectionInfo(){this.store.remove(yt.SELECTIONINFO)}saveAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let r=JSON.parse(n);r.push(t),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}else{let r=[];r.push(t),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return t}deleteAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.id!==t),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return t}deleteSelectedAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.highlight?.id!==t.highlight.id),this.store.set(yt.ANNOTATIONS,JSON.stringify(r))}return t}getAnnotations(){let t=this.store.get(yt.ANNOTATIONS);if(t){let n=JSON.parse(t);return n=n.sort((r,o)=>{if(r.locations.progression&&o.locations.progression)return r.locations.progression-o.locations.progression}),n}return[]}getAnnotationPosition(t,n){let r=this.store.get(yt.ANNOTATIONS);if(r){let a=JSON.parse(r).filter(l=>l.highlight?.id===t||l.id===t);if(a.length>0){let l=n.document.getElementById(`${a[0].highlight.id}`);if(l){let u=0;if(l.hasChildNodes)for(let d=0;d<l.childNodes.length;d++){let f=l.childNodes[d],g=parseInt(f.style.top.replace("px",""));(g<u||u===0)&&(u=g)}else u=parseInt(l.style.top.replace("px",""));return u}}}return null}getAnnotationElement(t,n){let r=this.store.get(yt.ANNOTATIONS);if(r){let a=JSON.parse(r).filter(l=>l.highlight?.id===t);if(a.length>0){let l=n.document.getElementById(`${a[0].highlight.id}`);if(l){let u=0;if(l.hasChildNodes)for(let d=0;d<l.childNodes.length;d++){let f=l.childNodes[d],g=parseInt(f.style.top.replace("px",""));if(g<u||u===0)return u=g,f}else u=parseInt(l.style.top.replace("px",""));return l}}}return null}getAnnotation(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let o=JSON.parse(n).filter(a=>a.highlight?.id===t.id);if(o.length>0)return o[0]}return null}getAnnotationByID(t){let n=this.store.get(yt.ANNOTATIONS);if(n){let o=JSON.parse(n).filter(a=>a.highlight?.id===t);if(o.length>0)return o[0]}return null}},lo=yt;lo.LAST_READING_POSITION="last-reading-position",lo.BOOKMARKS="bookmarks",lo.ANNOTATIONS="annotations",lo.SELECTIONINFO="selectionInfo";C();C();var Wd=class{constructor(){this.store={}}get(t){return this.store[t]||null}set(t,n){this.store[t]=n}remove(t){this.store[t]=null}};var Ys=class{constructor(t){this.prefix=t.prefix,this.useLocalStorage=t.useLocalStorage;try{let n=t.prefix+"-"+String(Math.random());this.useLocalStorage?(window.localStorage.setItem(n,"test"),window.localStorage.removeItem(n)):(window.sessionStorage.setItem(n,"test"),window.sessionStorage.removeItem(n)),this.fallbackStore=null}catch(n){this.fallbackStore=new Wd}}getLocalStorageKey(t){return this.prefix+"-"+t}get(t){let n;return this.fallbackStore?n=this.fallbackStore.get(t):this.useLocalStorage?n=window.localStorage.getItem(this.getLocalStorageKey(t)):n=window.sessionStorage.getItem(this.getLocalStorageKey(t)),n}set(t,n){this.fallbackStore?this.fallbackStore.set(t,n):this.useLocalStorage?window.localStorage.setItem(this.getLocalStorageKey(t),n):window.sessionStorage.setItem(this.getLocalStorageKey(t),n)}remove(t){this.fallbackStore?this.fallbackStore.remove(t):this.useLocalStorage?window.localStorage.removeItem(this.getLocalStorageKey(t)):window.sessionStorage.removeItem(this.getLocalStorageKey(t))}};C();var P3=Je(va()),I3=Je(Cn());var sl=class extends P3.Link{};sl=ac([(0,I3.JsonObject)()],sl);function al(i){let t,n,r,o;if(i instanceof Array)return i.map(function(a){return typeof a=="object"&&(a=al(a)),a});t={};for(n in i)i.hasOwnProperty(n)&&(r=(n.charAt(0).toLowerCase()+n.slice(1)||n).toString(),o=i[n],(o instanceof Array||o!==null&&o.constructor===Object)&&(o=al(o)),r==="href1"?t.href=o:r==="typeLink"?t.type=o:t[r]=o);return t}C();var L3=Je(Dt()),ig=class{constructor(t){this.LAYERSETTINGS="layerSetting";this.store=t,this.initialize()}static async create(t){let n=new this(t.store);return new Promise(r=>r(n))}async stop(){L3.default.log("MediaOverlay settings stop")}async initialize(){this.userProperties=await this.getLayerSettings()}async getLayerSettings(){let t=new Si,n=await this.store.get(this.LAYERSETTINGS);if(n){let r=JSON.parse(n);t.properties=r}return t}async saveProperty(t){let n=await this.store.get(this.LAYERSETTINGS);if(n){let r=JSON.parse(n);r=r.filter(o=>o.name!==t.name),r.push(t),await this.store.set(this.LAYERSETTINGS,JSON.stringify(r))}else{let r=[];r.push(t),await this.store.set(this.LAYERSETTINGS,JSON.stringify(r))}return new Promise(r=>r(t))}async getProperty(t){let n=await this.store.get(this.LAYERSETTINGS);if(n){let r=JSON.parse(n);return r=r.filter(o=>o.name===t),r.length===0?null:r[0]}return null}};C();var ll=Je(Dt()),og=class{static async create(t){let n=new this(t.delegate,t.publication,t,t.headerMenu);return await n.start(),n}constructor(t,n,r,o){this.headerMenu=o,this.delegate=t,this.publication=n,this.properties=r}async stop(){ll.default.log("Page Break module stop")}async start(){this.delegate.pageBreakModule=this,this.headerMenu&&(this.goToPageView=de(this.headerMenu,"#sidenav-section-gotopage")),this.headerMenu&&(this.goToPageNumberInput=de(this.headerMenu,"#goToPageNumberInput")),this.headerMenu&&(this.goToPageNumberButton=de(this.headerMenu,"#goToPageNumberButton")),ne(this.goToPageNumberInput,"keypress",this.goToPageNumber.bind(this)),ne(this.goToPageNumberButton,"click",this.goToPageNumber.bind(this)),this.goToPageView&&(this.publication.pageList?.length||this.goToPageView.parentElement?.removeChild(this.goToPageView)),setTimeout(()=>{this.properties.hideLayer?this.delegate.hideLayer("pagebreak"):this.delegate.showLayer("pagebreak")},10)}async goToPageNumber(t){if(this.goToPageNumberInput.value&&(t.key==="Enter"||t.type==="click")){var n=this.publication.pageList?.filter(o=>o.Href.slice(o.Href.indexOf("#")+1).replace(/[^0-9]/g,"")===this.goToPageNumberInput.value);if(n&&n.length>0){var r=n[0];let o={progression:0};if(r.Href.indexOf("#")!==-1){let l=r.Href.slice(r.Href.indexOf("#")+1);l!==null&&(o={fragment:l})}let a={href:this.publication.getAbsoluteHref(r.Href),locations:o,type:r.TypeLink,title:r.Title};this.delegate.goTo(a)}}}async handleResize(){await this.delegate.highlighter?.destroyHighlights(qe.PageBreak),await this.drawPageBreaks()}async drawPageBreaks(){setTimeout(()=>{let t=this.delegate.iframes[0].contentDocument?.body,n=t?.querySelectorAll('[*|type="pagebreak"]');n?.length===0&&(n=t?.querySelectorAll("[epub\\:type='pagebreak']"));let r=this;function o(a){try{let l=r.delegate.iframes[0].contentDocument;return l?Rn(a,l,no):""}catch(l){return ll.default.log("uniqueCssSelector:"),ll.default.error(l),""}}if(n)for(let a=0;a<n.length;a++){let l=n[a];ll.default.log(l);let u=l.innerHTML,d=!1;l.innerHTML.length===0&&(u=l.getAttribute("title")??"",l.innerHTML=u,d=!0),l.innerHTML.length===0&&(u=(l.getAttribute("id")??"").replace(/[^0-9]/g,""),l.innerHTML=u,d=!0);let f=this.delegate.iframes[0].contentDocument;if(f){let g=this.delegate.highlighter?.dom(f.body).getWindow().document.createRange(),y=this.delegate.highlighter?.dom(f.body).getSelection();if(y.removeAllRanges(),g.selectNodeContents(l),y.addRange(g),!y.isCollapsed){let v=Ri(g,o);y.removeAllRanges(),v&&this.createPageBreakHighlight({rangeInfo:v,cleanText:"",rawText:""},u)}}d&&(l.innerHTML="")}},200)}createPageBreakHighlight(t,n){try{let o=`${t.rangeInfo.startContainerElementCssSelector}${t.rangeInfo.startContainerChildTextNodeIndex}${t.rangeInfo.startOffset}${t.rangeInfo.endContainerElementCssSelector}${t.rangeInfo.endContainerChildTextNodeIndex}${t.rangeInfo.endOffset}`,a=Tr.hash(o),l="R2_PAGEBREAK_"+a;var r=!1;let u={color:"#000000",id:l,pointerInteraction:r,selectionInfo:t,marker:Le.Custom,icon:{id:"pageBreak",title:n,color:"#000000",position:"left"},type:qe.PageBreak};zt.push(u);let d=this.delegate.highlighter?.createHighlightDom(this.delegate.iframes[0].contentWindow,u);return u.position=parseInt((d?.hasChildNodes()?d.childNodes[0]:d).style.top.replace("px","")),u}catch(o){throw"Can't create highlight: "+o}}};C();var B3=Je(Xp());var k3=Je(Qi());var Ke=Je(Dt()),sg=class{constructor(t,n,r,o,a,l,u){this.voices=[];this.hasEventListener=!1;this.startX=0;this.startY=0;this.index=0;this.userScrolled=!1;this.scrollPartial=!1;this.speaking=!1;this.restartIndex=-1;this.ttsQueueIndex=-1;this.ttsQueue=void 0;this.ttsPlayQueueIndexDebounced=(0,k3.debounce)((t,n)=>{this.restartIndex>=0?(this.ttsQueueIndex=this.restartIndex,this.restartIndex=-1):this.ttsQueueIndex=t,this.ttsQueue=n,this.ttsPlayQueueIndex(this.ttsQueueIndex,n)},150);this.delegate=t,this.tts=n,this.headerMenu=u,this.rights=r,this.highlighter=o,this.properties=a,this.api=l}initialize(t){this.highlighter!==void 0&&(this.tts.setControls(),this.tts.onRestart(this.restart.bind(this)),this.body=t,this.clean=(0,B3.default)(this.body.innerHTML,{allowedTags:[],allowedAttributes:{}}),this.wrapper=dt(document,"#iframe-wrapper"),window.speechSynthesis.getVoices(),this.initVoices(!0),this.hasEventListener||(this.hasEventListener=!0,ne(document,"wheel",this.wheel.bind(this)),ne(this.body,"wheel",this.wheel.bind(this)),ne(document,"keydown",this.wheel.bind(this)),ne(this.delegate.iframes[0].contentDocument,"keydown",this.wheel.bind(this))),ne(this.body,"mousedown",this.clickStart.bind(this)),ne(this.body,"mouseup",this.click.bind(this)))}clickStart(t){"clientX"in t&&(this.startX=t.clientX),"clientY"in t&&(this.startY=t.clientY)}click(t){let n=0,r=0;if("clientX"in t&&(n=t.clientX),"clientY"in t&&(r=t.clientY),window.speechSynthesis.speaking&&this.speaking&&n===this.startX&&r===this.startY){let o=this.delegate.iframes[0].contentDocument;if(o){let a=this.highlighter.dom(o.body).getSelection();if(a.isCollapsed){let g=this.delegate.iframes[0].contentDocument,y=this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(g);a.addRange(y.range)}let l=a.getRangeAt(0),u=a.anchorNode;for(;l.toString().indexOf(" ")!==0;)try{l.setStart(u,l.startOffset-1)}catch(g){break}l.setStart(u,l.startOffset+1);do l.setEnd(u,u.length<l.endOffset?l.endOffset+1:u.length);while(l.toString().indexOf(" ")===-1&&l.toString().trim()!=="");let f=document.querySelector("main#iframe-wrapper iframe").contentWindow?.document.body;if(this.ttsQueue&&f){let g=this.findTtsQueueItemIndex(this.ttsQueue,a.anchorNode,a.anchorNode,a.anchorOffset,f);a.removeAllRanges(),g>=0&&(window.speechSynthesis.cancel(),this.restartIndex=g,this.ttsPlayQueueIndexDebounced(this.restartIndex,this.ttsQueue))}}}}initVoices(t){function n(){return new Promise(function(o,a){let l=window.speechSynthesis,u;u=setInterval(()=>{l.getVoices().length!==0&&(o(l.getVoices()),clearInterval(u))},10)})}n().then(async o=>{if(Ke.default.log(o),this.voices=[],o.forEach(l=>{l.localService===!0&&this.voices.push(l)}),Ke.default.log(this.voices),t&&this.headerMenu){var a=de(this.headerMenu,"#preferred-languages");a&&this.voices.forEach(l=>{var u=document.createElement("option");u.value=l.name+":"+l.lang,u.innerHTML=l.name+" ("+l.lang+")",a.add(u)})}})}cancel(t=!0){t&&(this.api?.stopped&&this.api?.stopped(),this.delegate.emit("readaloud.stopped","stopped")),this.userScrolled=!1,this.speaking=!1,setTimeout(()=>{window.speechSynthesis.cancel()},0),this._ttsQueueItemHighlightsWord&&(this.delegate.highlighter?.destroyHighlights(qe.ReadAloud),this._ttsQueueItemHighlightsWord=void 0)}async speak(t,n,r){this.api?.started&&this.api?.started(),this.delegate.emit("readaloud.started","started");let o=this;this.userScrolled=!1,this.cancel(!1);let a;if(n){let O=document.querySelector("main#iframe-wrapper iframe").contentWindow?.document.body,_=this.delegate.iframes[0].contentDocument;if(_){let A=this.highlighter.dom(_.body).getSelection();if(A.isCollapsed){let T=o.delegate.iframes[0].contentDocument,M=o.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(T);A.addRange(M.range)}if(O){var l=this.generateTtsQueue(O);if(!l.length)return;var u=this.findTtsQueueItemIndex(l,A.anchorNode,A.anchorNode,A.anchorOffset,O),d=this.findTtsQueueItemIndex(l,A.focusNode,A.focusNode,A.focusOffset,O);let T=Vo(l,u),M=Vo(l,d);var f;if(T&&t&&t.cleanText){let j=Jo(T),P=t.rangeInfo.startOffset,q=t.cleanText;if(M&&u+1===d){let k=Jo(M);P=(j+" "+k).indexOf(t.cleanText),q=j.slice(P,j.length),f=t.cleanText.replace(q,"").trim()}else if(d>u){let k="";for(let B=u+1;B<d;B++){let N=Vo(l,B);if(N){let W=Jo(N);k+=W,f=t.cleanText.replace(W,"")}}if(M){let B=Jo(M);k+=" "+B}P=(j+" "+k).indexOf(t.cleanText),q=j.slice(P,j.length),f=f.replace(q,"").trim()}a=new SpeechSynthesisUtterance(q),Ke.default.log(t),Ke.default.log(q,t.range?.commonAncestorContainer.textContent),Ke.default.log(T),Ke.default.log(T.item.textNodes),Ke.default.log(P),Ke.default.log(T.item.combinedText);let U=T.item.textNodes.filter(k=>k===t.range?.commonAncestorContainer)[0];Ke.default.log(U),a.onboundary=k=>{this.updateTTSInfo(T,k.charIndex,k.charLength,P,a.text)}}}}}else a=new SpeechSynthesisUtterance(this.clean);a.rate=this.tts.rate,a.pitch=this.tts.pitch,a.volume=this.tts.volume,Ke.default.log("this.tts.voice.lang",this.tts.voice.lang);var g=!0;this.tts.voice&&this.tts.voice.lang&&(g=this.tts.voice.lang.indexOf("-")!==-1,g===!1&&(this.tts.voice.lang=this.tts.voice.lang.replace("_","-"),g=!0)),Ke.default.log("initialVoiceHasHyphen",g),Ke.default.log("voices",this.voices);var y;g===!0?(y=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(E=>{var O=E.lang.replace("_","-");return O===this.tts.voice.lang&&E.name===this.tts.voice.name})[0]:void 0,y===void 0&&(y=this.tts.voice&&this.tts.voice.lang?this.voices.filter(E=>E.lang.replace("_","-")===this.tts.voice.lang)[0]:void 0)):(y=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(E=>E.lang===this.tts.voice.lang&&E.name===this.tts.voice.name)[0]:void 0,y===void 0&&(y=this.tts.voice&&this.tts.voice.lang?this.voices.filter(E=>E.lang===this.tts.voice.lang)[0]:void 0)),Ke.default.log("initialVoice",y);var v=o.delegate.publication.Metadata.Language[0].indexOf("-")!==-1;Ke.default.log("publicationVoiceHasHyphen",v);var S;v===!0?S=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(E=>{var O=E.lang.replace("_","-");return O.startsWith(o.delegate.publication.Metadata.Language[0])||O.endsWith(o.delegate.publication.Metadata.Language[0].toUpperCase())})[0]:void 0:S=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(E=>E.lang.startsWith(o.delegate.publication.Metadata.Language[0])||E.lang.endsWith(o.delegate.publication.Metadata.Language[0].toUpperCase()))[0]:void 0,Ke.default.log("publicationVoice",S);var w=navigator.language.indexOf("-")!==-1;Ke.default.log("defaultVoiceHasHyphen",w);var b;w===!0?b=this.voices.filter(E=>{var O=E.lang.replace("_","-");return O===navigator.language&&E.localService===!0})[0]:b=this.voices.filter(E=>{var O=E.lang;return O===navigator.language&&E.localService===!0})[0],b===void 0&&(b=this.voices.filter(E=>{var O=E.lang;return O.includes(navigator.language)&&E.localService===!0})[0]),Ke.default.log("defaultVoice",b),y?(Ke.default.log("initialVoice"),a.voice=y):S?(Ke.default.log("publicationVoice"),a.voice=S):b&&(Ke.default.log("defaultVoice"),a.voice=b),a.voice!==void 0&&a.voice!==null&&(a.lang=a.voice.lang,Ke.default.log("utterance.voice.lang",a.voice.lang),Ke.default.log("utterance.lang",a.lang)),Ke.default.log("navigator.language",navigator.language),setTimeout(()=>{window.speechSynthesis.speak(a)},0),this.index=0;function m(){a.onend=function(){if(d>u)if(u=u+1,u!==d){let E=Vo(l,u);if(E){let O=Jo(E);a=new SpeechSynthesisUtterance(O),a.onboundary=_=>{o.updateTTSInfo(E,_.charIndex,_.charLength,0,a.text)},setTimeout(()=>{window.speechSynthesis.speak(a)},0),m()}}else{let E=Vo(l,u);E&&(a=new SpeechSynthesisUtterance(f),a.onboundary=O=>{o.updateTTSInfo(E,O.charIndex,O.charLength,0,a.text)},setTimeout(()=>{window.speechSynthesis.speak(a)},0),m()),u>d&&(Ke.default.log("utterance ended"),o.highlighter.doneSpeaking(),o.api?.finished(),o.delegate.emit("readaloud.finished","finished"))}else Ke.default.log("utterance ended"),o.highlighter.doneSpeaking(),o.api?.finished(),o.delegate.emit("readaloud.finished","finished")}}m(),r()}speakPlay(){this.scrollPartial=!0,this.cancel(!1),this.api?.started&&this.api?.started(),this.delegate.emit("readaloud.started","started");let t=this,r=document.querySelector("main#iframe-wrapper iframe").contentWindow?.document.body;if(r){let l=function(){let u=t.highlighter.visibleTextRects[0],d=t.delegate.iframes[0].contentDocument;if(d){let f=t.highlighter.dom(d.body).getWindow().document.createRange(),g=t.highlighter.dom(t.delegate.iframes[0].contentDocument?.body).getSelection();g.removeAllRanges(),f.selectNodeContents(u.node),g.addRange(f);let y=0,v=g.focusNode,S=g.focusOffset;g.collapse(g.anchorNode,g.anchorOffset);for(let w=0;w<y;w++)g.modify("move","forward","line");if(g.extend(v,S),g.collapse(g.anchorNode,g.anchorOffset),r){let w=t.findTtsQueueItemIndex(o,g.anchorNode,g.anchorNode,g.anchorOffset,r);w>=0&&(a=w)}g.removeAllRanges()}},o=this.generateTtsQueue(r);if(!o.length)return;let a=0;l(),a<0&&(a=0),setTimeout(()=>{this.startTTSSession(o,a)},200)}}speakPause(){window.speechSynthesis.speaking&&(this.api?.paused&&this.api?.paused(),this.delegate.emit("readaloud.paused","paused"),this.userScrolled=!1,window.speechSynthesis.pause(),this.speaking=!1,this._ttsQueueItemHighlightsWord&&(this.delegate.highlighter?.destroyHighlights(qe.ReadAloud),this._ttsQueueItemHighlightsWord=void 0))}speakResume(){window.speechSynthesis.speaking&&(this.api?.resumed&&this.api?.resumed(),this.delegate.emit("readaloud.resumed","resumed"),this.userScrolled=!1,window.speechSynthesis.resume(),this.speaking=!0)}static async create(t){let n=new this(t.delegate,t.tts,t.rights,t.highlighter,t,t.api,t.headerMenu);return await n.start(),n}async start(){if(this.delegate.ttsModule=this,this.headerMenu){var t=de(this.headerMenu,"#menu-button-tts");t&&t.parentElement?.style.removeProperty("display")}setTimeout(()=>{this.properties?.hideLayer?this.delegate.hideLayer("readaloud"):this.delegate.showLayer("readaloud")},10)}wheel(t){if(t instanceof KeyboardEvent)switch(t.key){case"ArrowUp":this.userScrolled=!0;break;case"ArrowDown":this.userScrolled=!0;break}else this.userScrolled=!0}stop(){Ke.default.log("TTS module stop"),Pe(document,"wheel",this.wheel.bind(this)),Pe(this.body,"wheel",this.wheel.bind(this)),Pe(document,"keydown",this.wheel.bind(this)),Pe(this.delegate.iframes[0].contentDocument,"keydown",this.wheel.bind(this)),Pe(this.body,"click",this.click.bind(this))}generateTtsQueue(t){let n=[],r=[];function o(d){if(d.nodeType!==Node.TEXT_NODE||!d.nodeValue||!d.nodeValue.trim().length)return;let f=r[r.length-1];if(!f)return;let g=d.parentElement?N3(d.parentElement):void 0,y=d.parentElement?aN(d.parentElement):void 0,v=n[n.length-1];(!v||v.parentElement!==f||v.lang!==g||v.dir!==y)&&(v={combinedText:"",dir:y,lang:g,parentElement:f,textNodes:[]},n.push(v)),v.textNodes.push(d)}let a=!0;function l(d){if(d.nodeType!==Node.ELEMENT_NODE)return;let f=a||d.matches("h1, h2, h3, h4, h5, h6, p, th, td, caption, li, blockquote, q, dt, dd, figcaption, div, pre");a=!1,f&&r.push(d);for(let g of d.childNodes)switch(g.nodeType){case Node.ELEMENT_NODE:let y=g;if(!y.matches("img, sup, sub, audio, video, source, button, canvas, del, dialog, embed, form, head, iframe, meter, noscript, object, s, script, select, style, textarea"))l(y);else if(y.tagName&&y.tagName.toLowerCase()==="img"&&y.src){let S=y.getAttribute("alt");if(S){let w=S.trim();if(w){let b=N3(y),m=void 0;n.push({combinedText:w,dir:m,lang:b,parentElement:y,textNodes:[]})}}}break;case Node.TEXT_NODE:r.length!==0&&o(g);break;default:break}f&&r.pop()}l(t);function u(d){if(!d.textNodes||!d.textNodes.length){(!d.combinedText||!d.combinedText.length)&&(d.combinedText="");return}d.combinedText=lN(d.textNodes,!0).replace(/[\r\n]/g," ");let f=d.parentElement;for(;f;){if(f.tagName){let g=f.tagName.toLowerCase();if(g==="pre"||g==="code"||g==="video"||g==="audio")break}f=f.parentElement}}for(let d of n)u(d);return n}findTtsQueueItemIndex(t,n,r,o,a){let l=0;for(let u of t){if(r&&u.textNodes){if(u.textNodes.includes(r))return l}else if(n===u.parentElement||u.parentElement!==n.ownerDocument.body&&u.parentElement!==a&&u.parentElement.contains(n)||n.contains(u.parentElement))return l;l++}return-1}restart(){window.speechSynthesis.speaking&&(window.speechSynthesis.cancel(),this.restartIndex=this.ttsQueueIndex,this.ttsPlayQueueIndexDebounced(this.restartIndex,this.ttsQueue))}startTTSSession(t,n){if(!Vo(t,n)){this.cancel();return}this.speaking=!0,this.ttsPlayQueueIndexDebounced(n,t)}ttsPlayQueueIndex(t,n){if(t<0){this.cancel();return}let r=Vo(n,t);if(!r){this.cancel();return}let o=Jo(r);if(!o){this.cancel();return}let a=new SpeechSynthesisUtterance(o);a.rate=this.tts.rate,a.pitch=this.tts.pitch,a.volume=this.tts.volume,Ke.default.log("this.tts.voice.lang",this.tts.voice.lang);var l=!0;this.tts.voice&&this.tts.voice.lang&&(l=this.tts.voice.lang.indexOf("-")!==-1,l===!1&&(this.tts.voice.lang=this.tts.voice.lang.replace("_","-"),l=!0)),Ke.default.log("initialVoiceHasHyphen",l),Ke.default.log("voices",this.voices);var u;l===!0?(u=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(S=>{var w=S.lang.replace("_","-");return w===this.tts.voice.lang&&S.name===this.tts.voice.name})[0]:void 0,u===void 0&&(u=this.tts.voice&&this.tts.voice.lang?this.voices.filter(S=>S.lang.replace("_","-")===this.tts.voice.lang)[0]:void 0)):(u=this.tts.voice&&this.tts.voice.lang&&this.tts.voice.name?this.voices.filter(S=>S.lang===this.tts.voice.lang&&S.name===this.tts.voice.name)[0]:void 0,u===void 0&&(u=this.tts.voice&&this.tts.voice.lang?this.voices.filter(S=>S.lang===this.tts.voice.lang)[0]:void 0)),Ke.default.log("initialVoice",u);var d=this,f=d.delegate.publication.Metadata.Language[0].indexOf("-")!==-1;Ke.default.log("publicationVoiceHasHyphen",f);var g;f===!0?g=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(S=>{var w=S.lang.replace("_","-");return w.startsWith(d.delegate.publication.Metadata.Language[0])||w.endsWith(d.delegate.publication.Metadata.Language[0].toUpperCase())})[0]:void 0:g=this.tts.voice&&this.tts.voice.usePublication?this.voices.filter(S=>S.lang.startsWith(d.delegate.publication.Metadata.Language[0])||S.lang.endsWith(d.delegate.publication.Metadata.Language[0].toUpperCase()))[0]:void 0,Ke.default.log("publicationVoice",g);var y=navigator.language.indexOf("-")!==-1;Ke.default.log("defaultVoiceHasHyphen",y);var v;y===!0?v=this.voices.filter(S=>{var w=S.lang.replace("_","-");return w===navigator.language&&S.localService===!0})[0]:v=this.voices.filter(S=>{var w=S.lang;return w===navigator.language&&S.localService===!0})[0],v===void 0&&(v=this.voices.filter(S=>{var w=S.lang;return w.includes(navigator.language)&&S.localService===!0})[0]),Ke.default.log("defaultVoice",v),u?(Ke.default.log("initialVoice"),a.voice=u):g?(Ke.default.log("publicationVoice"),a.voice=g):v&&(Ke.default.log("defaultVoice"),a.voice=v),a.voice!==void 0&&a.voice!==null&&(a.lang=a.voice.lang,Ke.default.log("utterance.voice.lang",a.voice.lang),Ke.default.log("utterance.lang",a.lang)),Ke.default.log("navigator.language",navigator.language),a.onboundary=S=>{Ke.default.log(S.name),this.updateTTSInfo(r,S.charIndex,S.charLength,0,a.text)},setTimeout(()=>{window.speechSynthesis.speak(a),d.speaking||window.speechSynthesis.pause()},0),a.onend=function(){d.speaking&&d.ttsPlayQueueIndexDebounced(t+1,n)}}updateTTSInfo(t,n,r,o,a){if(!t)return;Ke.default.log(t,n,r,a);let l=a||Jo(t);if(n>=0&&a){let u=a.slice(0,n+1).search(/\S+$/),d=a.slice(n).search(/\s/),f=d<0?a.slice(u):a.slice(u,d+n),g=u+f.length;if(r===void 0){let y=a.substring(n).match(/^[a-z\d']*/i);y&&(r=y[0].length)}r===void 0&&(r=f.length),this.wrapHighlightWord(t,a,n+o,r,f,u,g)}return l}wrapHighlightWord(t,n,r,o,a,l,u){Ke.default.log(t),Ke.default.log(n),Ke.default.log(r,o,a,l,u),this._ttsQueueItemHighlightsWord&&(this.delegate.highlighter?.destroyHighlights(qe.ReadAloud),this._ttsQueueItemHighlightsWord=void 0);let d=t.item,f=r,g=0,y,v=-1,S,w=-1,b=f+o;for(let E of d.textNodes){if(!E.nodeValue&&E.nodeValue!=="")continue;let O=E.nodeValue.length;if(g+=O,y||f<g&&(y=E,v=O-(g-f)),y&&b<=g&&(S=E,w=O-(g-b)),S)break}if(y&&S){let O=function(T){try{let M=m.delegate.iframes[0].contentDocument;return M?Rn(T,M,no):""}catch(M){return Ke.default.log("uniqueCssSelector:"),Ke.default.error(M),""}},E=new Range;E.setStart(y,v),E.setEnd(S,w);var m=this;let _=Ri(E,O);if(!_)return;let A=this.delegate.highlighter?.createHighlight(this.delegate.iframes[0].contentWindow,{rangeInfo:_,cleanText:"",rawText:"",range:void 0},this.tts.color,!1,Le.Custom,{id:"tts",title:"",position:"right"},void 0,{defaultClass:this.tts.color},qe.ReadAloud,"R2_READALOUD_");if(A){this._ttsQueueItemHighlightsWord=A[0];let j=(A[1]?.firstChild?.getBoundingClientRect()).top-this.wrapper.scrollTop>window.innerHeight/2-65;this.delegate.view?.isScrollMode()&&this.tts.autoScroll&&!this.userScrolled&&this.scrollPartial&&j?A[1]?.firstChild?.scrollIntoView({block:"center",behavior:"smooth"}):this.delegate.view?.isPaginated()&&m.delegate.view?.snap(A[1]?.firstChild)}}}};function N3(i){let t=i;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let n=t.getAttribute("xml:lang");if(n||(n=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang")),n||(n=t.getAttribute("lang")),n)return n;t=t.parentNode}}function aN(i){let t=i;for(;t&&t.nodeType===Node.ELEMENT_NODE;){let n=t.getAttribute("dir");if(n)return n;t=t.parentNode}}function lN(i,t){if(i&&i.length){let n="";for(let r of i)r.nodeValue&&(n+=t?r.nodeValue:uN(r.nodeValue));return n}return""}function cN(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function uN(i){return cN(i).replace(/\n/g," ").replace(/\s\s+/g," ")}function Vo(i,t){let n=-1,r=-1;for(let o of i)if(r++,n++,t===n)return{item:o,iArray:r,iGlobal:n,iSentence:-1}}function Jo(i){return i.item.combinedText}C();var cl=Je(Ed());var H3=Je(Qi());var j3=Je(Dt()),ag=class{constructor(t,n,r,o,a){this.currentChapterPopupResult=[];this.currentPopupHighlights=[];this.definitions=(0,H3.debounce)(async()=>{if(await this.highlighter.destroyHighlights(qe.Definition),this.properties.definitions)for(let t of this.properties.definitions)await this.define(t)},200);this.delegate=t,this.publication=n,this.properties=r,this.api=a,this.highlighter=o}static async create(t){let n=new this(t.delegate,t.publication,t,t.highlighter,t.api);return await n.start(),n}async stop(){j3.default.log("Definitions module stop")}async start(){this.delegate.definitionsModule=this,setTimeout(()=>{this.properties.hideLayer?this.delegate.hideLayer("definitions"):this.delegate.showLayer("definitions")},10)}async searchAndPaint(t,n){let r=this.publication.getAbsoluteHref(this.publication.readingOrder?this.publication.readingOrder[this.delegate.currentResource()??0].Href:""),o=this.publication.getTOCItem(r);o===void 0&&this.publication.readingOrder&&(o=this.publication.readingOrder[this.delegate.currentResource()??0]);let a=[];if(o)for(let l of t.terms){let u=t.terms.indexOf(l);o&&await Js(l,this.delegate.iframes[0].contentDocument,o.Href,o.Title,this.delegate.definitionsModule?.properties.fullWordSearch).then(d=>{let f;t.result===1?f=0:t.result===2&&(f=Math.floor(Math.random()*d.length-1)+1),d.forEach((g,y)=>{if(f===void 0||f===y){let v={rangeInfo:g.rangeInfo},S=this.createDefinitionHighlight(v,t);g.highlight=S,a.push(cl.omit(S,"definition")),this.currentChapterPopupResult.push(g),this.currentPopupHighlights.push(S)}}),u===t.terms.length-1&&n(a)})}}async define(t){await this.searchAndPaint(t,async n=>{this.api?.success&&(this.api?.success(cl.omit(t,"callbacks"),n),this.delegate.emit("definition.success",n),this.api?.visible&&n.forEach(r=>{let a=this.delegate.iframes[0].contentDocument?.querySelector(`#${r.id}`)?.querySelectorAll(`.${hn}`),l=new IntersectionObserver((u,d)=>{u.forEach(f=>{f.intersectionRatio===1&&(this.api?.visible(cl.omit(t,"callbacks"),cl.omit(r,"definition")),this.delegate.emit("definition.visible",t,r))})},{threshold:1});a&&a.length>0&&l.observe(a[0])}))})}async drawDefinitions(){setTimeout(async()=>{await this.definitions()},100)}async handleResize(){await this.drawDefinitions()}createDefinitionHighlight(t,n){try{let r=this.delegate.definitionsModule?.properties.color;De.isHexColor(r)&&(r=De.hexToRgbChannels(r));let o=`${t.rangeInfo.startContainerElementCssSelector}${t.rangeInfo.startContainerChildTextNodeIndex}${t.rangeInfo.startOffset}${t.rangeInfo.endContainerElementCssSelector}${t.rangeInfo.endContainerChildTextNodeIndex}${t.rangeInfo.endOffset}`,a=Tr.hash(o),l="R2_DEFINITION_"+a;this.highlighter.destroyHighlight(this.delegate.iframes[0].contentDocument,l);let u={color:r||Fo,id:l,pointerInteraction:!0,selectionInfo:t,marker:Le.Underline,type:qe.Definition};zt.push(u);let d=this.highlighter.createHighlightDom(this.delegate.iframes[0].contentWindow,u);return d&&(n.definition&&(d.dataset.definition=n.definition),d.dataset.order=String(n.order),u.definition=n,u.position=parseInt((d?.hasChildNodes()?d.childNodes[0]:d).style.top.replace("px",""))),u}catch(r){throw"Can't create definitions highlight: "+r}}async addDefinition(t){await this.define(t)}async clearDefinitions(){await this.highlighter.destroyHighlights(qe.Definition)}};C();var co=Je(Dt()),D3=.5,Gd=class{constructor(t,n,r,o){this.hasEventListener=!1;this.lines=[];this.index=0;this.isActive=!1;this.isDebug=!1;this.lineFocusContainer=document.getElementById("lineFocusContainer");this.readerContainer=document.getElementById("D2Reader-Container");this.lineFocusTopBlinder=document.getElementById("lineFocusTopBlinder");this.lineFocusBottomBlinder=document.getElementById("lineFocusBottomBlinder");this.wrapperHeight=void 0;this.delegate=t,this.properties=n,this.api=o,this.highlighter=r}static async create(t){let n=new this(t.delegate,t,t.highlighter,t.api);return await n.start(),n}async stop(){co.default.log("Definitions module stop"),this.hasEventListener=!1,Pe(document,"keydown",this.keydown.bind(this)),Pe(document,"keyup",this.keyup.bind(this)),Pe(this.delegate.iframes[0].contentDocument,"keydown",this.keydown.bind(this)),Pe(this.delegate.iframes[0].contentDocument,"keyup",this.keyup.bind(this))}async start(){this.delegate.lineFocusModule=this;let t=dt(document,"#iframe-wrapper");t.style.height.length>0&&(this.wrapperHeight=t.style.height,this.lineFocusContainer&&this.lineFocusContainer.style.height.length===0&&(this.lineFocusContainer.style.height=this.wrapperHeight),this.readerContainer&&this.readerContainer.style.height.length===0&&(this.readerContainer.style.height=this.wrapperHeight),this.readerContainer&&(this.readerContainer.style.overflow="hidden")),this.hasEventListener||(this.hasEventListener=!0,ne(document,"keydown",this.keydown.bind(this)),ne(document,"keyup",this.keyup.bind(this)),ne(this.delegate.iframes[0].contentDocument,"keydown",this.keydown.bind(this)),ne(this.delegate.iframes[0].contentDocument,"keyup",this.keyup.bind(this)))}keydown(t){if(t instanceof KeyboardEvent&&this.isActive)switch(t.key){case"ArrowUp":t.stopPropagation();break;case"ArrowDown":t.stopPropagation();break}}keyup(t){if(t instanceof KeyboardEvent&&this.isActive)switch(t.key){case"ArrowUp":this.lineUp();break;case"ArrowDown":this.lineDown();break}}handleResize(){this.isActive&&this.lineFocus()}async enableLineFocus(){this.isActive=!0,await this.delegate.settings.scroll(!0),this.lineFocus()}disableLineFocus(t=!0){this.isActive=!1;let n=dt(document,"#iframe-wrapper");this.wrapperHeight&&(n.style.height=this.wrapperHeight),t||(this.index=0);let r=this.delegate.iframes[0].contentDocument;Qt(r,"html").style.removeProperty("--USER__maxMediaHeight"),this.wrapperHeight=void 0,this.lineFocusContainer&&(this.lineFocusContainer.style.display="none");let a=document.getElementById("container-view-timeline");a&&a.style.removeProperty("display");let l=document.getElementById("divBefore");l&&l.remove();let u=document.getElementById("divAfter");u&&u.remove(),this.highlighter.destroyHighlights(qe.LineFocus)}lineFocus(){let t=dt(document,"#iframe-wrapper"),n=this.delegate.iframes[0].contentDocument,r=Qt(n,"html"),o=this.properties.maxHeight?Fr()*this.properties.maxHeight/100:Fr()/2;r.style.setProperty("--USER__maxMediaHeight",o+"px");function a(g,y){g.parentNode.insertBefore(y,g.nextSibling)}function l(g,y){g.parentNode.insertBefore(y,g)}let u=document.getElementById("container-view-timeline");u&&(u.style.display="none"),this.lineFocusContainer&&this.lineFocusContainer.style.removeProperty("display");let d=document.getElementById("divBefore");if(d)d.style.height=t.clientHeight/2+"px";else{let g=document.createElement("div");g.style.height=t.clientHeight/2+"px",g.id="divBefore",l(t,g)}let f=document.getElementById("divAfter");if(f)f.style.height=t.clientHeight/2+"px";else{let g=document.createElement("div");g.style.height=t.clientHeight/2+"px",g.id="divAfter",a(t,g)}if(this.lines=[],n){let v=function(){let O=Math.round,_=Math.random,A=255;return{blue:O(_()*A),green:O(_()*A),red:O(_()*A)}},S=function(O,_){let A=[];for(let T=0,M=0;T<O.length;T++)T>=_&&T%_==0&&M++,A[M]=A[M]||[],A[M].push(O[T]);return A},w=function(O,_){let A=Math.min(O.left,_.left),T=Math.max(O.right,_.right),M=Math.min(O.top,_.top),j=Math.max(O.bottom,_.bottom);return{bottom:j,height:j-M,left:A,right:T,top:M,width:T-A}},b=function(O){if(O.length>1){let _=w(O[0],O[1]);if(O.length>2){let A=w(_,O[2]);if(O.length>3){let T=w(A,O[3]);return O.length>4?w(T,O[4]):T}return A}return _}return O[0]},g=this.findRects(n.body);g=i0(g,!0),g=g.sort(function(O,_){return O.top-_.top});let y=[];g=g.filter(function(O){let _=O.top;return y.indexOf(_)===-1&&y.indexOf(_+1)===-1&&y.indexOf(_+2)===-1&&y.indexOf(_+3)===-1&&y.indexOf(_+4)===-1&&y.indexOf(_-1)===-1&&y.indexOf(_-2)===-1&&y.indexOf(_-3)===-1&&y.indexOf(_-4)===-1?(y.push(_),!0):!1}),this.highlighter.destroyHighlights(qe.LineFocus);let m=[];this.properties.lines&&this.properties.lines>1?S(g,this.properties.lines).forEach(_=>{m.push(b(_))}):m=g;let E=de(n,"#"+Re.R2_ID_LINEFOCUS_CONTAINER);if(E)for(let O of m){let _=document.createElement("div");_.setAttribute("class",hn);let A=v();if(De.isHexColor(A)&&(A=De.hexToRgbChannels(A)),this.isDebug){let he=`border-bottom: 1px solid rgba(${A.red}, ${A.green}, ${A.blue}, ${D3}) !important`;_.setAttribute("style",`mix-blend-mode: multiply; border-radius: 1px !important; background-color: rgba(${A.red}, ${A.green}, ${A.blue}, ${D3}) !important; ${he}`)}_.style.outline="none",_.tabIndex=0;let T=this.delegate.iframes[0].contentWindow.document,M=this.delegate.view.isPaginated();M?T.body.style.position="revert":T.body.style.position="relative";let j=T.body.getBoundingClientRect(),P=this.highlighter.getScrollingElement(T),q=M?-P.scrollLeft:j.left,U=M?-P.scrollTop:j.top,k=1,B=24,N,W,ye=this.delegate.iframes[0].contentWindow?.innerWidth,be=parseInt(getComputedStyle(n.documentElement).getPropertyValue("column-count")),fe=parseInt(getComputedStyle(n.documentElement).getPropertyValue("column-width")),re=parseInt(getComputedStyle(n.body).getPropertyValue("padding-left"));if(ye){let he=ye/(be||1);he<fe&&(he=ye),M||(he=parseInt(getComputedStyle(n.body).width.replace("px","")));let Ae=this.delegate.settings.fontSize/100,ue=20*Ae;Ae<=1&&(ue=-60);let Oe=0;Ae<=1&&(Oe=-60),N=Math.floor(O.left/he)*he+he-(B<40?40:B)+Oe,W=Math.floor(O.left/he)*he+(B<40?40:B)-ue;let Ce=parseInt(n.documentElement.style.getPropertyValue("--USER__pageMargins"));Ce>=2&&(W=W+re/be,N=N-re/be),M||(N=parseInt(getComputedStyle(n.body).width.replace("px","")),W=parseInt(getComputedStyle(n.body).width.replace("px",""))-he,Ce>=2&&(W=W+re/2,N=N-re/2))}_.style.setProperty("pointer-events","none"),_.style.position="absolute",_.scale=k,_.rect={height:O.height,left:O.left-q,top:O.top-U,width:O.width},_.style.width=`${_.rect.width*k}px`,_.style.height=`${_.rect.height*k}px`,_.style.left=`${_.rect.left*k}px`,_.style.top=`${_.rect.top*k}px`,this.lines.push(_),E.append(_)}setTimeout(()=>{this.currentLine()},100)}}currentLine(){let t=this.lines[this.index],n=t.style.top,o=parseInt(t.style.top.replace("px",""))+parseInt(t.style.height.replace("px",""))-parseInt(n.replace("px",""));if(this.lineFocusContainer){let l=(parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px",""))-o)/2;this.lineFocusTopBlinder&&(this.lineFocusTopBlinder.style.height=l+"px"),this.lineFocusBottomBlinder&&(this.lineFocusBottomBlinder.style.height=l+"px")}t.scrollIntoView({block:"center",behavior:"smooth"})}lineDown(){if(this.index<this.lines.length-1){this.index+=1,this.index>this.lines.length-1&&(this.index=this.lines.length-1);let t=this.lines[this.index],n=t.style.top,o=parseInt(t.style.top.replace("px",""))+parseInt(t.style.height.replace("px",""))-parseInt(n.replace("px",""));if(this.lineFocusContainer){let l=(parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px",""))-o)/2;this.lineFocusTopBlinder&&(this.lineFocusTopBlinder.style.height=l+"px"),this.lineFocusBottomBlinder&&(this.lineFocusBottomBlinder.style.height=l+"px")}t.scrollIntoView({block:"center",behavior:"smooth"})}}lineUp(){if(this.index>0){this.index-=1,this.index<0&&(this.index=0);let t=this.lines[this.index],n=t.style.top,o=parseInt(t.style.top.replace("px",""))+parseInt(t.style.height.replace("px",""))-parseInt(n.replace("px",""));if(this.lineFocusContainer){let l=(parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px",""))-o)/2;this.lineFocusTopBlinder&&(this.lineFocusTopBlinder.style.height=l+"px"),this.lineFocusBottomBlinder&&(this.lineFocusBottomBlinder.style.height=l+"px")}t.scrollIntoView({block:"center",behavior:"smooth"})}}almostEqual(t,n,r){return Math.abs(t-n)<=r}findRects(t){let n=this.findTextNodes(t),r=Array.from(t.getElementsByTagName("img")),o=[];return n.forEach(a=>{o.push(...this.measureTextNodes(a))}),r.forEach(a=>{o.push(...this.measureImageNodes(a))}),o}findTextNodes(t,n=[]){let r=t.firstChild;for(;r;)r.nodeType===1&&this.findTextNodes(r,n),r.nodeType===3&&r.textContent?.trim()&&(r.textContent.trim().length>1||r.parentElement?.tagName.toLowerCase()==="h1"||r.parentElement?.tagName.toLowerCase()==="h2"||r.parentElement?.tagName.toLowerCase()==="h3"||r.parentElement?.tagName.toLowerCase()==="h4"||r.parentElement?.tagName.toLowerCase()==="h5"||r.parentElement?.tagName.toLowerCase()==="h6")&&r.parentElement&&getComputedStyle(r.parentElement).verticalAlign==="baseline"&&n.push(r),r=r.nextSibling;return n}measureTextNodes(t){try{let n=document.createRange();n.selectNodeContents(t);let r=Array.from(n.getClientRects());return n.detach(),r}catch(n){co.default.log("measureTextNode "+n),co.default.log("measureTextNode "+t),co.default.log(`${t.textContent}`)}}measureImageNodes(t){try{let n=document.createRange();n.selectNode(t);let r=Array.from(n.getClientRects());return n.detach(),r}catch(n){co.default.log("measureTextNode "+n),co.default.log("measureTextNode "+t),co.default.log(`${t.textContent}`)}}};C();var Vd=Je(Dt()),lg=class{constructor(t,n,r,o,a){this.history=[];this.headerMenu=a,this.delegate=n,this.publication=r,this.properties=o,this.annotator=t}static async create(t){let n=new this(t.annotator,t.delegate,t.publication,t,t.headerMenu);return await n.start(),n}async stop(){Vd.default.log("Page Break module stop"),Pe(this.historyForwardAnchorElement,"click",this.handleHistoryForwardClick.bind(this)),Pe(this.historyBackAnchorElement,"click",this.handleHistoryBackClick.bind(this))}async handleResize(){await this.setup()}setup(){this.history.length>0&&(this.historyForwardAnchorElement&&this.historyCurrentIndex+1<this.history.length?this.historyForwardAnchorElement.className=this.historyForwardAnchorElement.className.replace(" disabled",""):this.historyForwardAnchorElement&&(this.historyForwardAnchorElement.removeAttribute("href"),this.historyForwardAnchorElement.className+=" disabled"),this.historyBackAnchorElement&&this.historyCurrentIndex>0?this.historyBackAnchorElement.className=this.historyBackAnchorElement.className.replace(" disabled",""):this.historyBackAnchorElement&&(this.historyBackAnchorElement.removeAttribute("href"),this.historyBackAnchorElement.className+=" disabled"))}async push(t,n){let r;if(n&&this.annotator){let o=await this.annotator.getLastReadingPosition();if(o&&o.locations.progression&&o.locations.progression>0&&(this.historyCurrentIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyCurrentIndex)),r=this.history[this.history.length-1],r&&r.href!==o.href||r===void 0)){let a=this.publication.getAbsoluteHref(o.href);Vd.default.log(o.href),Vd.default.log(a),o.href=a,this.history.push(o),this.historyCurrentIndex=this.history.length-1}this.historyCurrentIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyCurrentIndex)),r=this.history[this.history.length-1],(r&&r.href!==t.href||r===void 0)&&(this.history.push(t),this.historyCurrentIndex=this.history.length-1)}}async start(){this.delegate.historyModule=this,this.headerMenu&&(this.historyForwardAnchorElement=de(this.headerMenu,"#history-forward")),this.headerMenu&&(this.historyBackAnchorElement=de(this.headerMenu,"#history-back")),this.historyCurrentIndex=this.history.length-1,ne(this.historyForwardAnchorElement,"click",this.handleHistoryForwardClick.bind(this)),ne(this.historyBackAnchorElement,"click",this.handleHistoryBackClick.bind(this))}async handleHistoryForwardClick(t){this.history.length>0&&this.historyCurrentIndex+1<this.history.length&&(this.historyCurrentIndex=this.historyCurrentIndex+1,await this.delegate.navigate(this.history[this.historyCurrentIndex],!1)),t.preventDefault(),t.stopPropagation()}async handleHistoryBackClick(t){this.history.length>0&&this.historyCurrentIndex>0&&(this.historyCurrentIndex=this.historyCurrentIndex-1,await this.delegate.navigate(this.history[this.historyCurrentIndex],!1)),t.preventDefault(),t.stopPropagation()}};C();var F3=Je(Dt()),it;(function(r){r[r.Chicago=0]="Chicago",r[r.MLA=1]="MLA",r[r.APA=2]="APA"})(it||(it={}));var $3;(function(o){o.Author="Author",o.Editor="Editor",o.Translator="Translator",o.Compiler="Compiler"})($3||($3={}));var Jd=class{constructor(t,n,r,o,a){this.highlighter=r,this.delegate=t,this.properties=o,this.publication=n,this.api=a}static async create(t){let n=new this(t.delegate,t.publication,t.highlighter,t,t.api);return await n.start(),n}async stop(){F3.default.log("Timeline module stop")}copyToClipboard(t){let n=!0;if(window.clipboardData)window.clipboardData.setData("text/plain",t);else{let r=this.createElementForExecCommand(t);this.selectContent(r);try{window.netscape&&netscape.security&&netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"),n=document.execCommand("copy",!1)}catch(o){n=!1}document.body.removeChild(r)}n?this.api?.citationCreated("The text was copied to the clipboard!"):this.api?.citationFailed("Your browser doesn't allow clipboard access!")}createElementForExecCommand(t){let n=document.createElement("div");return n.style.position="absolute",n.style.left="-10000px",n.style.top="-10000px",n.innerHTML=t,document.body.appendChild(n),n.contentEditable=!0,n}selectContent(t){let n=document.createRange();n.selectNodeContents(t);let r=window.getSelection();r?.removeAllRanges(),r?.addRange(n)}async start(){this.delegate.citationModule=this;let t=this,n={id:"citationIcon",callback:function(r){let o=function(){let P="",q="",U="";return t.publication.Metadata.Author?.length>0&&0===0&&t.publication.Metadata.Author[0].Name&&t.publication.Metadata.Author[0].Name.length>0&&(U=U+t.publication.Metadata.Author[0].Name,q=q+t.publication.Metadata.Author[0].Name,P=P+t.publication.Metadata.Author[0].Name),U.length>0&&q.length>0&&P.length>0?[P+". ",q+". ",U+". "]:["","",""]},a=function(){let P="",q="",U="";return t.publication.Metadata.Publisher&&t.publication.Metadata.Publisher[0].Name&&(q=q+t.publication.Metadata.Publisher[0].Name+", ",P=P+t.publication.Metadata.Publisher[0].Name+", "),t.publication.Metadata.PublicationDate&&t.publication.Metadata.PublicationDate.getFullYear()>0&&(U=U+"("+t.publication.Metadata.PublicationDate.getFullYear()+")",q=q+t.publication.Metadata.PublicationDate.getFullYear(),P=P+t.publication.Metadata.PublicationDate.getFullYear()),U.length>0&&q.length>0&&P.length>0?[P+". ",q+". ",U+". "]:["","",""]},l=function(){return t.publication.Metadata.Title?[t.publication.Metadata.Title+". ",t.publication.Metadata.Title+". ",t.publication.Metadata.Title+". "]:["","",""]},u=function(){return["","",""]},d=function(){let P="",q="",U="";return t.publication.Metadata.Publisher&&t.publication.Metadata.Publisher[0].Name&&(q=q+t.publication.Metadata.Publisher[0].Name+", ",P=P+t.publication.Metadata.Publisher[0].Name+", ",U=U+t.publication.Metadata.Publisher[0].Name+", "),U.length>0&&q.length>0&&P.length>0?[P+". ",q+". ",U+". "]:["","",""]},f=function(){return["","",""]},g=function(){return["","",""]},y=function(){return["","",""]},v=function(){return t.properties.library?["Retrieved from "+t.properties.library+". ","Retrieved from "+t.properties.library+". ","Retrieved from "+t.properties.library+". "]:["","",""]},S=function(){return t.properties.appName?[t.properties.appName+". ",t.properties.appName+". ",t.properties.appName+". "]:["","",""]},w=function(){return t.properties.appLink?[t.properties.appLink+". ",t.properties.appLink+". ",t.properties.appLink+". "]:["","",""]},b=function(){return["","",""]},m=function(P,q){return P.length>q?P.substring(0,q)+"...":P},E=o()[0]+l()[0]+f()[0]+u()[0]+y()[0]+a()[0]+g()[0]+v()[0]+S()[0]+w()[0],O=o()[2]+a()[2]+l()[2]+u()[2]+d()[2]+f()[2]+g()[2]+y()[2]+v()[2]+S()[2]+w()[2],_=o()[1]+l()[1]+f()[1]+u()[1]+y()[1]+a()[1]+b()[1]+v()[1]+S()[1]+w()[1],A="\u201C"+m(r,t.properties.characters)+"\u201C<br><br><em>"+E+"</em>",T="\u201C"+m(r,t.properties.characters)+"\u201C<br><br><em>"+O+"</em>",M="\u201C"+m(r,t.properties.characters)+"\u201C<br><br><em>"+_+"</em>",j="";t.properties.styles?.includes(it[0])&&(j=j+"Chicago: <br>"+A+"<br><br>"),t.properties.styles?.includes(it[2])&&(j=j+"APA: <br>"+T+"<br><br>"),t.properties.styles?.includes(it[1])&&(j=j+"MLA: <br>"+M+"<br><br>"),t.copyToClipboard(j)}};this.highlighter?.addSelectionMenuItem(n)}};var Ko=class{constructor(t,n,r,o,a,l,u,d,f,g,y,v,S,w,b,m,E){this.settings=t;this.navigator=n;this.highlighter=r;this.bookmarkModule=o;this.annotationModule=a;this.ttsSettings=l;this.ttsModule=u;this.searchModule=d;this.definitionsModule=f;this.contentProtectionModule=g;this.timelineModule=y;this.mediaOverlaySettings=v;this.mediaOverlayModule=S;this.pageBreakModule=w;this.lineFocusModule=b;this.historyModule=m;this.citationModule=E;this.startReadAloud=()=>{this.navigator.startReadAloud()};this.stopReadAloud=()=>{this.navigator.stopReadAloud()};this.pauseReadAloud=()=>{this.navigator.pauseReadAloud()};this.resumeReadAloud=()=>{this.navigator.resumeReadAloud()};this.startReadAlong=()=>{this.navigator.startReadAlong()};this.stopReadAlong=()=>{this.navigator.stopReadAlong()};this.pauseReadAlong=()=>{this.navigator.pauseReadAlong()};this.resumeReadAlong=()=>{this.navigator.resumeReadAlong()};this.saveBookmark=async()=>await this.bookmarkModule?.saveBookmark()??!1;this.saveBookmarkPlus=async()=>this.bookmarkModule?.saveBookmarkPlus();this.deleteBookmark=async t=>await this.bookmarkModule?.deleteBookmark(t)??!1;this.deleteAnnotation=async t=>await this.annotationModule?.deleteAnnotation(t)??!1;this.addAnnotation=async t=>await this.annotationModule?.addAnnotation(t)??!1;this.hideAnnotationLayer=()=>this.annotationModule?.hideAnnotationLayer();this.showAnnotationLayer=()=>this.annotationModule?.showAnnotationLayer();this.hideLayer=t=>this.navigator?.hideLayer(t);this.showLayer=t=>this.navigator?.showLayer(t);this.activateMarker=(t,n)=>this.navigator?.activateMarker(t,n);this.deactivateMarker=()=>this.navigator?.deactivateMarker();this.clearDefinitions=async()=>{await this.definitionsModule?.clearDefinitions()};this.addDefinition=async t=>{await this.definitionsModule?.addDefinition(t)};this.search=async(t,n)=>await this.searchModule?.search(t,n)??[];this.goToSearchIndex=async(t,n,r)=>{this.navigator.rights.enableSearch&&await this.searchModule?.goToSearchIndex(t,n,r)};this.goToSearchID=async(t,n,r)=>{this.navigator.rights.enableSearch&&await this.searchModule?.goToSearchID(t,n,r)};this.clearSearch=async()=>{this.navigator.rights.enableSearch&&await this.searchModule?.clearSearch()};this.resetUserSettings=async()=>await this.settings.resetUserSettings();this.applyUserSettings=async t=>await this.settings.applyUserSettings(t);this.scroll=async t=>await this.settings.scroll(t);this.increase=async t=>{this.isTTSIncrementable(t)?this.navigator.rights.enableTTS&&await this.ttsSettings?.increase(t):this.isMOIncrementable(t)?this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.increase(t):await this.settings.increase(t)};this.decrease=async t=>{this.isTTSIncrementable(t)?this.navigator.rights.enableTTS&&await this.ttsSettings?.decrease(t):this.isMOIncrementable(t)?this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.decrease(t):await this.settings.decrease(t)};this.resetTTSSettings=()=>{this.navigator.rights.enableTTS&&this.ttsSettings?.resetTTSSettings()};this.applyTTSSettings=async t=>{this.navigator.rights.enableTTS&&await this.ttsSettings?.applyTTSSettings(t)};this.applyPreferredVoice=async t=>{this.navigator.rights.enableTTS&&await this.ttsSettings?.applyPreferredVoice(t)};this.resetMediaOverlaySettings=async()=>{this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.resetMediaOverlaySettings()};this.applyMediaOverlaySettings=async t=>{this.navigator.rights.enableMediaOverlays&&await this.mediaOverlaySettings?.applyMediaOverlaySettings(t)};this.goTo=async t=>{this.navigator.goTo(t)};this.goToPosition=async t=>this.navigator.goToPosition(t);this.goToPage=async t=>{await this.navigator.goToPage(t)};this.nextResource=()=>{this.navigator.nextResource()};this.previousResource=()=>{this.navigator.previousResource()};this.nextPage=async()=>{this.navigator.nextPage()};this.previousPage=async()=>{this.navigator.previousPage()};this.snapToSelector=async t=>{this.navigator.snapToSelector(t)};this.applyAttributes=t=>{this.navigator.applyAttributes(t)};this.stop=()=>{document.body.onscroll=()=>{},this.navigator.stop(),this.settings.stop(),this.ttsSettings?.stop(),this.ttsModule?.stop(),this.bookmarkModule?.stop(),this.annotationModule?.stop(),this.searchModule?.stop(),this.definitionsModule?.stop(),this.contentProtectionModule?.stop(),this.timelineModule?.stop(),this.mediaOverlaySettings?.stop(),this.mediaOverlayModule?.stop(),this.pageBreakModule?.stop(),this.lineFocusModule?.stop()}}addEventListener(){this.navigator.addListener(arguments[0],arguments[1])}static async load(t){let n=t.rights??{autoGeneratePositions:!1,enableAnnotations:!1,enableBookmarks:!1,enableContentProtection:!1,enableDefinitions:!1,enableLineFocus:!1,enableMediaOverlays:!1,enablePageBreaks:!1,enableSearch:!1,enableTTS:!1,enableTimeline:!1,customKeyboardEvents:!1,enableHistory:!1,enableCitations:!1};n.enableContentProtection&&t.protection&&await jd.setupPreloadProtection(t.protection);let r=dt(document,"#D2Reader-Container"),o=de(document,"#headerMenu"),a=de(document,"#footerMenu"),l=t.url,u;t.publication?(u=Ts(t.publication,Ji),u.manifestUrl=new URL(l)):u=await Ji.fromUrl(l,t.requestConfig);let d=new Ys({prefix:u.manifestUrl,useLocalStorage:t.useLocalStorage??!1}),f=new Ys({prefix:"r2d2bc-reader",useLocalStorage:t.useLocalStorage??!1}),g=new Ys({prefix:"r2d2bc-layers",useLocalStorage:t.useLocalStorage??!1}),y=new lo({store:d});u.sample=t.sample,n=dN(n,u),n.autoGeneratePositions?await u.autoGeneratePositions(t.requestConfig):(t.services?.positions&&await u.fetchPositionsFromService(t.services?.positions.href,t.requestConfig),t.services?.weight&&await u.fetchWeightsFromService(t.services?.weight.href,t.requestConfig));let v=await ig.create({store:g}),S=await No.create({store:f,initialUserSettings:t.userSettings,headerMenu:o,api:t.api,injectables:(u.Metadata.Rendition?.Layout??"unknown")==="fixed"?t.injectablesFixed:t.injectables,layout:(u.Metadata.Rendition?.Layout??"unknown")==="fixed"?"fixed":"reflowable"}),w=await Ln.create({mainElement:r,headerMenu:o,footerMenu:a,publication:u,settings:S,annotator:y,initialLastReadingPosition:t.lastReadingPosition,api:t.api,rights:n,tts:t.tts,sample:t.sample,requestConfig:t.requestConfig,injectables:(u.Metadata.Rendition?.Layout??"unknown")==="fixed"?t.injectablesFixed??[]:t.injectables,attributes:t.attributes,services:t.services}),b=await De.create(Fe({delegate:w,layerSettings:v},t.highlighter)),m=n.enableBookmarks?await el.create(Fe({annotator:y,headerMenu:o,rights:n,publication:u,delegate:w,initialAnnotations:t.initialAnnotations},t.bookmarks)):void 0,E=n.enableAnnotations?await Qa.create(Fe({annotator:y,rights:n,publication:u,delegate:w,initialAnnotations:t.initialAnnotations,highlighter:b,headerMenu:o},t.annotations)):void 0,O=n.enableTTS,_=O?await ng.create({store:f,initialTTSSettings:t.tts,headerMenu:o}):void 0,A;O&&_&&(A=await sg.create(Fe({delegate:w,tts:_,headerMenu:o,rights:n,highlighter:b},t.tts)));let T=n.enableSearch?await tg.create(Fe({headerMenu:o,delegate:w,publication:u,highlighter:b},t.search)):void 0,M=n.enableDefinitions?await ag.create(Fe({delegate:w,publication:u,highlighter:b},t.define)):void 0,j=n.enableTimeline?await L0.create({publication:u,delegate:w}):void 0,P=n.enableContentProtection?await jd.create(Fe({delegate:w},t.protection)):void 0,q=n.enableMediaOverlays,U=q?await M0.create(Fe({store:f,initialMediaOverlaySettings:t.mediaOverlays,headerMenu:o},t.mediaOverlays)):void 0,k=q?await P0.create(Fe({publication:u,delegate:w,settings:U},t.mediaOverlays)):void 0,N=n.enablePageBreaks&&u.isReflowable?await og.create(Fe({publication:u,headerMenu:o,delegate:w},t.pagebreak)):void 0,W=n.enableLineFocus?await Gd.create(Fe({publication:u,delegate:w,highlighter:b},t.lineFocus)):void 0,ye=n.enableHistory?await lg.create({annotator:y,publication:u,delegate:w,headerMenu:o}):void 0,be=n.enableCitations?await Jd.create(Fe({publication:u,delegate:w,highlighter:b},t.citations)):void 0;return new Ko(S,w,b,m,E,_,A,T,M,P,j,U,k,N,W,ye,be)}get hasMediaOverlays(){return this.navigator.hasMediaOverlays}get tableOfContents(){return al(this.navigator.tableOfContents())??[]}get readingOrder(){return al(this.navigator.readingOrder())??[]}get bookmarks(){return this.bookmarkModule?.getBookmarks()??[]}get annotations(){return this.annotationModule?.getAnnotations()}get currentResource(){return this.navigator.currentResource()}get mostRecentNavigatedTocItem(){return this.navigator.mostRecentNavigatedTocItem()}get totalResources(){return this.navigator.totalResources()}get publicationLanguage(){return this.navigator.publication.Metadata.Language}get currentSettings(){return this.settings.currentSettings}isTTSIncrementable(t){return t==="pitch"||t==="rate"||t==="volume"}isMOIncrementable(t){return t==="mo_rate"||t==="mo_volume"}get currentLocator(){return this.navigator.currentLocator()}get positions(){return this.navigator.positions()}get atStart(){return this.navigator.atStart()}get atEnd(){return this.navigator.atEnd()}async applyLineFocusSettings(t){if(t.lines&&this.lineFocusModule){let n=this.lineFocusModule.properties.lines??1;this.lineFocusModule.index=this.lineFocusModule.index*n/parseInt(t.lines),this.lineFocusModule.index=Math.abs(parseInt(this.lineFocusModule.index.toFixed())),this.lineFocusModule.properties.lines=parseInt(t.lines),this.lineFocusModule.isActive&&await this.lineFocusModule.enableLineFocus()}t.debug!==void 0&&this.lineFocusModule&&(this.lineFocusModule.isDebug=t.debug,this.lineFocusModule.isActive&&await this.lineFocusModule.enableLineFocus())}lineUp(){this.lineFocusModule?.lineUp()}lineDown(){this.lineFocusModule?.lineDown()}async enableLineFocus(){await this.lineFocusModule?.enableLineFocus()}async lineFocus(t){t?await this.lineFocusModule?.enableLineFocus():this.lineFocusModule?.disableLineFocus()}disableLineFocus(){this.lineFocusModule?.disableLineFocus()}};function dN(i,t){return t.isFixedLayout&&(i.enableAnnotations=!1,i.enableSearch=!1,i.enableTTS=!1,i.enableDefinitions=!1,i.enablePageBreaks=!1,i.enableLineFocus=!1),t.sample?.isSampleRead&&(i.enableAnnotations=!1,i.enableSearch=!1,i.enableTTS=!1,i.enableDefinitions=!1,i.enableTimeline=!1,i.enableMediaOverlays=!1,i.enablePageBreaks=!1,i.enableLineFocus=!1),i}var fN=Ko,hN=Ko.load;return pN;})();
|
|
83
83
|
/*!
|
|
84
84
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
85
85
|
*
|