application.register("fictioneer-chapter",classextendsStimulus.Controller{staticgettargets(){return["bookmarkScroll","contentWrapper","index","content"]}staticvalues={chapterId:Number,storyId:Number};startClick=0;lastToolsParagraph=null;tools=_$$$("paragraph-tools");progressBar=_$(".progress__bar");hasPassword=!!_$("article._password");checkmarkUpdated=!1;checkboxProgressBar=_$$$("site-setting-chapter-progress-bar");checkboxMinimalist=_$$$("site-setting-minimal");initialize(){this.progressBar&&this.hasContentTarget&&!this.hasPassword&&(this.trackProgress(),window.addEventListener("scroll.rAF",FcnUtils.throttle(this.trackProgress.bind(this),1e3/48)))}connect(){window.FictioneerApp.Controllers.fictioneerChapter=this,this.hasIndexTarget&&this.indexTargets.forEach((t=>{t.querySelector(`[data-id="${this.chapterIdValue}"]`)?.classList.add("current")}))}clickOutside({detail:{target:t}}){this.lastToolsParagraph&&!t.closest(".selected-paragraph")&&this.closeTools()}scrollToBookmark(){constt=window.FictioneerApp.Controllers.fictioneerBookmarks;if(!t)returnvoidfcn_showNotification("Error: Bookmarks Controller not connected.",3,"warning");conste=t.data()?.[`ch-${this.chapterIdValue}`]?.["paragraph-id"];if(!e)return;constn=_$(`[data-paragraph-id="${e}"]`);n?.scrollIntoView({behavior:"smooth"})}openFullscreen(){document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.webkitRequestFullscreen&&document.documentElement.webkitRequestFullscreen()}closeFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}toggleTools(t){this.lastToolsParagraph?.classList.remove("selected-paragraph"),this.lastToolsParagraph!==t?(this.lastToolsParagraph=t,t.classList.add("selected-paragraph"),t.append(this.tools)):this.closeTools()}closeTools(){this.lastToolsParagraph?.classList.remove("selected-paragraph"),this.lastToolsParagraph=null}fastClick(t){""==window.getSelection().toString()&&(this.startClick=Date.now(),document.addEventListener("mouseup",(()=>{Date.now()<this.startClick+400&&this.#t(t.target)&&this.tools&&this.toggleTools(t.target.closest("p"))}),{once:!0}))}quote(t){conste=t.target.closest("p[data-paragraph-id]");if(!e)return;constn=window.getSelection()?window.getSelection().toString().trim():"",s=`[anchor]${e.id}[/anchor]`;leta=FcnUtils.extractTextNodes(e);if(a.length>16&&n.replace(/\s/g,"").length){constt=Math.ceil(.25*n.length);lete=fictioneer_tl.partial.quoteFragmentPrefix,s=fictioneer_tl.partial.quoteFragmentSuffix;n.startsWith(a.substring(0,t+1))&&(e=""),n.endsWith(a.substring(a.length-t,a.length))&&(s=""),a=`${e}${n}${s}`}fcn_showNotification(fictioneer_tl.notification.quoteAppendedToComment),FcnUtils.appendToComment(`\n[quote]${a}${s}[/quote]\n`)}toggleBookmark({target:t}){conste=window.FictioneerApp.Controllers.fictioneerBookmarks;e?(e.toggle(t.closest("p[data-paragraph-id]").dataset.paragraphId,t.closest("[data-color]")?.dataset.color??"none"),window.matchMedia("(min-width: 1024px)").matches&&this.closeTools()):fcn_showNotification("Error: Bookmarks Controller not connected.",3,"warning")}copyLink(t){conste=t.target.closest("p[data-paragraph-id]");e&&FcnUtils.copyToClipboard(`${location.protocol}//${location.host}${location.pathname}#${e.id}`,fictioneer_tl.notification.linkCopiedToClipboard)}toggleIndexOrder({currentTarget:t}){conste=t.closest(".chapter-index");e.dataset.order="asc"===e.dataset.order?"desc":"asc"}trackProgress(){if(!this.progressBar||!this.hasContentTarget||this.hasPassword||this.checkboxMinimalist.checked||!(this.checkboxProgressBar?.checked??1))return;constt=this.contentTarget.getBoundingClientRect(),e=t.height,n=e-t.bottom-Math.max(t.top,0)+window.innerHeight;lets=100*n/e;if(document.body.classList.toggle("hasProgressBar",!(s<0||n>e+500)),s=FcnUtils.clamp(0,100,s),this.progressBar.style.width=`${s}%`,!this.checkmarkUpdated&&this.hasStoryIdValue&&this.storyIdValue&&s>=100&&FcnUtils.loggedIn()){if(this.checkmarkUpdated=!0,!this.hasChapterIdValue||!this.chapterIdValue||"fu